4

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?

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

2 Answers 2

2

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

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .