[systemd-devel] Restarting service starts stopped dependants

Adam Zegelin adam at instaclustr.com
Mon Feb 9 00:25:34 PST 2015


Hi list,

Is the following expected behaviour?

Given services A, B, and C.

C "Requires" A & B.

All units are inactive.

`systemctl restart A` activates C, which in turn activates B.
Whereas `systemctl start A` activates A and only A. C and B are left inactive.



I can understand that starting C should start both A and B as they are Required dependencies.
But I can’t grasp why *restarting* A should start C, if C is stopped. And then by extension why B should start.

See below for example commands & output.

Regards,
Adam


core at core-01 /etc/systemd/system $ find . -maxdepth 1 \( -name A.service -or -name B.service -or -name C.service \) -print -exec cat {} \;
./A.service
[Unit]

[Service]
ExecStart=/bin/bash -c 'while true; do echo this is service A; sleep 1; done'

[Install]
WantedBy=multi-user.target


./B.service
[Unit]

[Service]
ExecStart=/bin/bash -c 'while true; do echo this is service B; sleep 1; done'

[Install]
WantedBy=multi-user.target


./C.service
[Unit]

Requires=A.service B.service

[Service]
ExecStart=/bin/bash -c 'while true; do echo this is service C; sleep 1; done'

[Install]
WantedBy=multi-user.target


core at core-01 /etc/systemd/system $ systemctl status --lines=0 A B C
● A.service
Loaded: loaded (/etc/systemd/system/A.service; disabled; vendor preset: disabled)
Active: inactive (dead) since Mon 2015-02-09 07:12:45 UTC; 8min ago
Main PID: 20871 (code=killed, signal=TERM)
CGroup: /system.slice/A.service

● B.service
Loaded: loaded (/etc/systemd/system/B.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Mon 2015-02-09 07:12:45 UTC; 8min ago
Main PID: 20867 (code=killed, signal=TERM)
CGroup: /system.slice/B.service

● C.service
Loaded: loaded (/etc/systemd/system/C.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Mon 2015-02-09 07:12:45 UTC; 8min ago
Main PID: 20866 (code=killed, signal=TERM)
CGroup: /system.slice/C.service
core at core-01 /etc/systemd/system $ sudo systemctl restart A
core at core-01 /etc/systemd/system $ systemctl status --lines=0 A B C
● A.service
Loaded: loaded (/etc/systemd/system/A.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2015-02-09 07:21:31 UTC; 1s ago
Main PID: 21196 (bash)
CGroup: /system.slice/A.service
        ├─21196 /bin/bash -c while true; do echo this is service A; sleep 1; done
        └─21201 sleep 1

● B.service
Loaded: loaded (/etc/systemd/system/B.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2015-02-09 07:21:31 UTC; 1s ago
Main PID: 21194 (bash)
CGroup: /system.slice/B.service
        ├─21194 /bin/bash -c while true; do echo this is service B; sleep 1; done
        └─21200 sleep 1

● C.service
Loaded: loaded (/etc/systemd/system/C.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2015-02-09 07:21:31 UTC; 1s ago
Main PID: 21195 (bash)
CGroup: /system.slice/C.service
        ├─21195 /bin/bash -c while true; do echo this is service C; sleep 1; done
        └─21202 sleep 1
core at core-01 /etc/systemd/system $ systemctl --version
systemd 218
-PAM -AUDIT -SELINUX +IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP -GCRYPT -GNUTLS -ACL -XZ -LZ4 +SECCOMP +BLKID -ELFUTILS +KMOD -IDN




core at core-01 /etc/systemd/system $ sudo systemctl stop A B C
core at core-01 /etc/systemd/system $ sudo systemctl start A
core at core-01 /etc/systemd/system $ systemctl status --lines=0 A B C
● A.service
Loaded: loaded (/etc/systemd/system/A.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2015-02-09 07:35:17 UTC; 1s ago
Main PID: 23972 (bash)
CGroup: /system.slice/A.service
        ├─23972 /bin/bash -c while true; do echo this is service A; sleep 1; done
        └─23974 sleep 1

● B.service
Loaded: loaded (/etc/systemd/system/B.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Mon 2015-02-09 07:35:13 UTC; 4s ago
Process: 21194 ExecStart=/bin/bash -c while true; do echo this is service B; sleep 1; done (code=killed, signal=TERM)
Main PID: 21194 (code=killed, signal=TERM)
CGroup: /system.slice/B.service

● C.service
Loaded: loaded (/etc/systemd/system/C.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Mon 2015-02-09 07:35:13 UTC; 4s ago
Process: 23830 ExecStart=/bin/bash -c while true; do echo this is service C; sleep 1; done (code=killed, signal=TERM)
Main PID: 23830 (code=killed, signal=TERM)
CGroup: /system.slice/C.service




More information about the systemd-devel mailing list