When node-red terminates normally (ie not a crash) it terminates processes running in exec nodes. Does it do this by sending a particular signal or does node red rely on the system to close down spawned processes?
The reason for asking is that I am running the duplicity backup s/w with rsync as the backend. If I stop node-red then it terminates duplicity and also any rsync processes that duplicity has spawned. That is ok as duplicity is designed to be able restart from partial backups. If I want to pause the backup without stopping node red then I can kill it by sending msg.kill to the exec node. If I use SIGINT or SIGTERM then duplicity is killed, but rsync is left running. That is undesirable as the backup could be restarted while rsync is still writing the partial backup, which doesn't seem like a good idea. I don't want to use SIGTERM as then duplicity does not have a chance to clean up.
As is often the case, no sooner have I posted a question than I find how to answer the question myself. I suspect it is down to how KillMode is configured in the systemd script, as defined in systemd.kill
Hi @Colin - the exec node can be called with msg.kill and will accept whatever signal you need - but the default on shutdown is just .kill() which does indeed use SIGTERM. So if you know you are going to shutdown you may be able to kill it cleanly first...
Do you actually want to kill the backup or would you prefer to leave it running?
If you want to leave it running even if Node-RED goes away, I think you can simply run it with & after the command so that it spawns an independent process?
To prevent multiple instances from running, I'd wrap the backup in a shell script and start the processes from there capturing the PID's in a pid file, deleting the pid file on completion. Then you can check at the start of the script to see if the pid file exists and decline to start another instance.
No, I don't want to leave it running, quite the reverse. I want to pause the backup in order to stop it using up bandwidth if we are streaming video. It does work ok as it is, it is just that rsync keeps running for several minutes and if the backup were restarted in that time I feel it might be bad. I wonder whether running duplicity from a bash script might make it kill the spawned processes when I kill the script. I will try that tomorrow.
Well putting the duplicity call in a bash script didn't help, in fact it made it worse. It didn't even kill off duplicity when I sent the kill message to the exec node.