- Run the service as a non-root-user
- The service has a startup phase and you want to start the next startup scripts after this startup phase
# cat /lib/systemd/system/TEST.serviceThe service startup scripts have to look like this:
[Unit]
Description=MyTestSystemdConfiguration
[Service]
User=schroff
Type=notify
ExecStart=/home/schroff/bin/test.sh
NotifyAccess=all
$ cat /home/schroff/bin/test.shIn the startup phase you will get the following:
#!/bin/bash
echo Starting serivce
sleep 10
#Starting your services
echo Services started
/bin/systemd-notify --ready
echo Notify done
while test 1 do
sleep 600
done
#keep this scripts running, as long your service runs
schroff@zerberus:~/bin$ systemctl status TEST.serviceAnd after the startup phase this is the output (if there were no errors):
● TEST.service - MyTestSystemdConfiguration
Loaded: loaded (/lib/systemd/system/TEST.service; static; vendor preset: enabled)
Active: activating (start) since 19:39:27 CET; 7s ago
Main PID: 17390 (test.sh)
Tasks: 2 (limit: 4915)
Memory: 532.0K::
CPU: 7ms
CGroup: /system.slice/TEST.service
├─17390 /bin/bash /home/schroff/bin/test.sh
└─17395 sleep 10
19:39:27 zerberus systemd[1]: Starting MyTestSystemdConfiguration...
19:39:27 zerberus test.sh[17390]: Starting serivce
schroff@zerberus:~/bin$ systemctl status TEST.serviceBut sometime you will get:
● TEST.service - MyTestSystemdConfiguration
Loaded: loaded (/lib/systemd/system/TEST.service; static; vendor preset: enabled)
Active: active (running) since 19:38:38 CET; 3s ago
Main PID: 17242 (test.sh)
Tasks: 2 (limit: 4915)
Memory: 932.0K
CPU: 9ms
CGroup: /system.slice/TEST.service
├─17242 /bin/bash /home/schroff/bin/test.sh
└─17259 sleep 600
19:38:28 zerberus systemd[1]: Starting MyTestSystemdConfiguration...
19:38:28 zerberus test.sh[17242]: Starting serivce
19:38:38 zerberus test.sh[17242]: Services started
19:38:38 zerberus systemd[1]: Started MyTestSystemdConfiguration.
19:38:38 zerberus test.sh[17242]: Notify done
# systemctl restart TEST.service
Job for TEST.service failed because a timeout was exceeded.
See "systemctl status TEST.service" and "journalctl -xe" for details.
19:44:46 zerberus systemd[1]: TEST.service: Start operation timed out. Terminating.
19:44:46 zerberus systemd[1]: Failed to start MyTestSystemdConfiguration.
-- Subject: Unit TEST.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit TEST.service has failed.
--
-- The result is failed.
19:44:46 zerberus systemd[1]: TEST.service: Unit entered failed state.
19:44:46 zerberus systemd[1]: TEST.service: Failed with result 'timeout'.
Note that this will happen after 600s (default). You can change this with the parameter (systemd configuration, see manpage systemd.service)
TimeoutSecBut changing this Parameter will not help, because systemd status will never enter the state "active (running)".
The problem is systemd-notify doesn't work, since it lives too short (Redhat Bugzilla).
A workaround is described in that bug entry:
Instead of
systemd-notify --readyuse
python -c "import systemd.daemon, time; systemd.daemon.notify('READY=1'); time.sleep(5)"
No comments:
Post a Comment