I have two services A.service and B.service. I want B to be stopped when A exits/get killed/is stopped. Also, I want B to get restarted when A gets restarted. I tried out the answer given in How to start and stop a systemd unit with another? and set my files up as follows:-
A.service
[Unit]
Description=A
Before=B.service
Requires=B.service
[Service]
ExecStart=/usr/share/A
ExecStopPost=/usr/evo/exit_handler.sh %p
Restart=always
StartLimitBurst=3
StartLimitInterval=300
B.service
[Unit]
Description=B
BindsTo=A.service
[Service]
Type=forking
ExecStart=/usr/share/B start
ExecStop=/usr/share/B stop
StartLimitBurst=5
StartLimitInterval=10
Restart=always
When I kill A or do a systemctl restart A, I see that B gets restarted. But when A exits with status 0, I don't see B getting restarted. I have enabled systemd debug loggin and I see that the state of A changes to dead but not to auto-restart