1

Suppose I have two different "runlevels" setup via "targets" in systemd - before.target (a minimum bootstrap set of services enabled) and after.target (run everything).

Right now I do this when I want to switch from "before" to "after":

# Set default to after.target. 
/usr/bin/systemctl set-default after.target 1>/dev/null

# Before reboot make sure essential services are enabled
/usr/bin/systemctl enable foo bar baz buz 1>/dev/null

# Reboot
reboot

How can I get foo.service, bar.service, baz.service, and buz.service added to after.target when they are installed?

If I want to configure boz to run when after.target is enabled, is there any way to do that without modifying the /usr/lib/systemd/system/after.target file?

In older systems with chkconfig I would just enable the bootstrap services on say, runlevel 4, and then enable all other services on runlevel 3 but I'm having trouble figuring out how to do that here and would prefer not to have to hardcode in Wanted-By: after.target in all my service files.

1 Answer 1

2

This is suggested in the systemctl man page:

systemctl add-wants after.target foo.service

The man page states:

       add-wants TARGET UNIT..., add-requires TARGET UNIT...
           Adds "Wants=" or "Requires=" dependencies, respectively, to the
           specified TARGET for one or more units.

           This command honors --system, --user, --runtime and --global in a
           way similar to enable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .