[Unit]
Description=+++++++++++App start/stop+++++++++++++++++
After=network.target

[Service]
User=root
Group=root
StandardOutput=null
ExecStart=/usr/local/bin/app_start > /dev/null
Restart=always
RestartSec=120
ExecStop=/usr/local/bin/app_start_stop
KillMode=control-group
TimeoutStopSec=10

[Install]
WantedBy=multi-user.target

Can anyone suggest why my systemd script is not working?

  • After Running sudo systemctl daemon-reexec all running services received signal while reboot but if i reboot without this command systemctl daemon-reexec not able to receive SIGINTorSIGTERM signal in process. – Shilesh Babu Aug 28 at 16:01

Why do you bother with receiving signals? systemd will do all this for you with systemctl start app_start and systemctl stop app_start. I don't know what your script do and why do you need to do special things with ExecStop=/usr/local/bin/app_start_stop to stop the service app_start but there are some things that should be noted when app_start fails. app_start_stop will not execute then (1). User and Group is default root, also KillMode=control-group so you can omit this. Because network.target is a static unit it is important you use Wants= for it. You also suppress any output. I would not do that because you cannot see any (error) messages. By default they will go into the journal. You can look at it with

pi ~$ journalctl --unit app_start.service

Without knowing what your script do I would set up the unit as follows:

[Unit]
Description=+++++++++++App start/stop+++++++++++++++++
After=network.target
Wants=network.target

[Service]
ExecStart=/usr/local/bin/app_start
Restart=always
RestartSec=120
ExecStop=/usr/local/bin/app_start_stop
TimeoutStopSec=10

[Install]
WantedBy=multi-user.target

With all the timing conditions it is difficult to see what happens with the service app_start particularly when it fails or it is killed with TimeoutStopSec and then the app_start_stop isn't executed but the service starts again after 120 seconds. I would try to make a more stable script.


references:
[1] man systemd.service

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.