Understanding systemd "Requires=" option

This is tricky. The main thing to understand is that systemd starts everything in parallel, unless told not to. This is actually stated in the man page in the "Requires" section:

requirement dependencies do not influence the order in which services are started or stopped

What you want to achieve is "wait for a.service to be started before starting b.service". For this you need both the "Requires" and "After" options in your b.service file:

[Unit]
Requires=a.service
After=a.service

[Service]
ExecStart=/bin/sleep 1000

= UPDATE =

OK, I see what's wrong: in your a.service file you put the ExecStart command and didn't specify the Type. This means that the Type will default to 'Simple'. You need the type 'Forking' for this to work. From systemd.service man page:

If set to simple (the default if neither Type= nor BusName=, but ExecStart= are specified), it is expected that the process configured with ExecStart= is the main process of the service. In this mode, if the process offers functionality to other processes on the system, its communication channels should be installed before the daemon is started up (e.g. sockets set up by systemd, via socket activation), as systemd will immediately proceed starting follow-up units.

If set to forking, it is expected that the process configured with ExecStart= will call fork() as part of its start-up. The parent process is expected to exit when start-up is complete and all communication channels are set up. The child continues to run as the main daemon process. This is the behavior of traditional UNIX daemons. If this setting is used, it is recommended to also use the PIDFile= option, so that systemd can identify the main process of the daemon. systemd will proceed with starting follow-up units as soon as the parent process exits.

Therefore, you should update your a.service file to include 'Type=Forking':

[Service]
Type=forking
ExecStart=/bin/false

This will work. :)

Tags:

Systemd