I have two systemd services A and B . I want B to get executed after A but only if A exists else just execute B .
ExecStart. The commands and arguments executed when the service starts. ExecStartPre, ExecStartPost. Additional commands that are executed before or after the command in ExecStart . ExecReload.
multi-user. target: This target is often used as the default target a system starts in. It starts everything that is needed for full system functionality and is commonly used on servers. graphical.
systemd targets are different states that your system can boot into, comparable to System V runlevels. Unlike SysV runlevels, target units are named rather than numbered. For example, the graphical. target is comparable to SysV runlevel 5, multiuser with network and a graphical environment.
The database server requires a Services file, which contains information about the known services on your network. The Services file is typically located in %windir%\System32\drivers\etc\services.
You need to add in your B.service file:
After=A.service
Or you can add to A.service:
Before=B.service
From SystemD documentation:
Before=, After=
These two settings expect a space-separated list of unit names. They configure ordering dependencies between units. If a unit foo.service contains a setting Before=bar.service and both units are being started, bar.service's start-up is delayed until foo.service has finished starting up. Note that this setting is independent of and orthogonal to the requirement dependencies as configured by Requires=, Wants= or BindsTo=.
Documentation source: https://www.freedesktop.org/software/systemd/man/systemd.unit.html
SerivceB
needs to include Wants=
directive for ServiceA
. Unit
section of ServiceB.service
file would look something like this:
[Unit]
Description=ServiceB description
Wants=ServiceA.service
From https://www.freedesktop.org/software/systemd/man/systemd.unit.html
Wants= A weaker version of Requires=. Units listed in this option will be started if the configuring unit is. However, if the listed units fail to start or cannot be added to the transaction, this has no impact on the validity of the transaction as a whole. This is the recommended way to hook start-up of one unit to the start-up of another unit.
Note that dependencies of this type may also be configured outside of the unit configuration file by adding symlinks to a .wants/ directory accompanying the unit file. For details, see above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With