I have two systemd services a
and b
, where b
is "After" and "BindsTo" a
, and b
is a short command that is launched every minute with a systemd timer.
Heres my config:
$ cat /systemd/a.service
[Unit]
After=foo
BindsTo=foo
[Service]
ExecStart=/opt/a/bin/a
Group=lev
User=lev
Restart=Always
WorkingDirectory=/opt/a
$ cat /systemd/b.service
[Unit]
After=a
BindsTo=a
[Service]
ExecStart=/opt/b/bin/b
Group=lev
User=lev
WorkingDirectory=/opt/b
$ cat /systemd/b.timer
[Unit]
[Timer]
OnCalendar=*:0/1:00
When I run sudo systemctl stop a
, service a
is indeed stopped, but then it is started back up at the top of the next minute when the timer for service b
runs b
The systemd documentation states that BindsTo
declares that if the unit bound to is stopped, this unit will be stopped too.
(https://www.freedesktop.org/software/systemd/man/systemd.unit.html#BindsTo=)
I expect that by stopping a
, b
will also be stopped, and the timer disabled. This is not the case. Can you help explain why the b
timer restarts not only b
(which should fail), but also a
?
Can you also help me edit these services such that:
- on boot, a is started first, then b is started
- when I
sudo systemctl stop a
,b
's timer does not run - when I
sudo systemctl start a
,b
's timer begins running again
Thanks in advance!