How to track all child processes spawned by a systemctl service

I have a system service

[Unit]
Description=dynsock server
After=network.target

[Service]
EnvironmentFile=/etc/dynsock.env
ExecStart=/usr/local/bin/dynctl.sh $SERVER $COUNT $BASEPORT $AUTH
ExecStop=/usr/local/bin/dynsock_onfailure.sh down
Restart=always
Type=forking

[Install]
Alias=dynsock.service

dynctl.sh will start $count child process. I hope when some process dead, systemctl will restart, and exec ExecStop . But system will only restart until all child process dead.


systemctl can't possibly know the ways dynctl.sh is forking so that it could know how many child processes must be alive at a given time. That's why you have to manage the life cycle of the processes, so that when one child process is dead, the service will be restarted.

I suggest using the main process as a master for the other ones, so that by using grep or pgrep it could determine if all children processes are alive, and if not it will give the comand systemctl restart <your service>.

Cheers, hope it helps