I'm trying to create dependencies between two services described in `systemd` unit files:
* a.service has to start before b.service
* b.service can not start if a.service fails
Here is what I have:
% cat a.service
[Unit]
Description=A-Service
Before=b.service
[Service]
ExecStart=/opt/a.sh
[Install]
WantedBy=multi-user.target
% cat b.service
[Unit]
Description=B-Service
After=a.service
[Service]
ExecStart=/opt/b.sh
[Install]
WantedBy=multi-user.target
And this are simple scripts executed for service A and B:
% cat a.sh
#!/bin/sh
echo "A service started"
exit 0
% cat b.sh
#!/bin/sh
echo "B service started"
exit 0
So I've tried to emulate a/service failure by returning `exit 1` from `a.sh`, `systemctl status a.service` reports it as failed:
Active: failed (Result: exit-code) ...
Process: 843 ExecStart=/opt/a.sh (code=exited, status=1/FAILURE)
...
However b.service still starts:
% systemctl status b.service
...
Active: inactive (dead) ...
Process: 844 ExecStart=/opt/b.sh (code=exited, status=0/SUCCESS)
...
What am I doing wrong? Is it a problem with the scripts or [Unit] definition is not complete?