I have a python program that runs as a systemd user service. From that program, I launch external commands via
subprocess.Popen(cmd, close_fds=True, start_new_session=True)
. My intention is for these new processes to stay running even after the parent service stops or restarts. This works completely fine when I run my program directly from the terminal, but when it's run as a systemd service, these processes get killed along with the parent program upon service restart.
I tried nohup
and double forking to no avail. I noticed that when double forking, the child process ends up having the systemd --user
as a parent, not init
as is the case when run simply from a terminal.
Am I missing something obvious? Is there a better way for a systemd service to launch external programs so that they're independent from it? Let me know if there's more info I should provide.
Asked by czert
(1 rep)
Nov 8, 2023, 04:07 PM