I have a systemd service to run a monitoring bash script which is started by a systemd timer. I've used
Type=oneshot which seems the most appropriate. However, sometimes the script needs to call another program, which happens to fork. Once it does that, the script is done and exits, but once the script exits, systemd will kill all the remaining child processes.
I could use
KillMode=process to prevent that, but then there's a risk that in other paths through the script other processes (that don't fork) could remain running after exit.
What's the best way to deal with this?
By the way, the forking program is dhcpcd, but I think the question applies generally. dhcpcd was originally started by ifplugd and this script is a failsafe just in case the system ends up in a state where dhcpcd isn't running anymore.