3

I have a systemd service unit:

[Unit]
After=network.target

[Service]
User=<user>
Type=forking
ExecStart=/opt/app/start.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target

The /opt/app/start.sh starts several processes and forks them:

for i in 1 2 3 4 5; do
    bash another_script.sh &
done

All of the things works fine, until one of the bash another_script.sh processes exits with non zero status. I expect that systemd service should restart in this situation. Is there any way to watch control-group failures and restart service if this happens?

  • systemd does nothing because your script - start.sh - has not failed. – fpmurphy Mar 17 '17 at 10:00
1

Control groups are not jobs.

There is no such thing as a "control group failure". Control groups are just collections used for resource limiting. They do not "fail".

What failure that there is here, is a failure to design a service properly. If one has multiple dæmon processes to monitor, and one wants the service manager to restart them individually if they terminate, then one should be defining multiple services.

Further reading

0

From help wait:

If the -n option is supplied, waits for the next job to terminate and returns its exit status.

So you should be able to use wait -n in your script to know when any of the jobs have finished.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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