Python launch subprocess in background

broken image
broken image
broken image

You should note that echo.py sticks around for 10 seconds and you can launch multiple processes. Now you can write to it: echo test | socat - /run/echo.sock You should confirm it’s there with ls -l /run/echo.sock and that it’s owned by Foreman with mode 0600. Then running systemctl daemon-reload & systemctl enable -now echo.socket will start the socket and let it listen on /run/echo.sock. You would create /etc/systemd/system/echo.socket It means systemd opens a unix socket to listen on. Subprocess.Popen(,shell=False,stdin=None,stdout=None,stderr=None,close_fds=True) Hostname = HOOK_JSON.get('host').get('name', None) (HOOK_EVENT, HOOK_OBJECT, HOOK_TEMP_DIR, get_json_hook) However, when it runs as part of the provisioning workflow, it waits on that child process finishing, I don’t understand why.Ĭhild process runs in background and workflow continues without waiting for it to complete When I run this hook from the command line it runs as expected, the parent python script exits and the child process is running in the background. This python script fires off a long running job supposedly in the background and I don’t wish to wait for it to complete before moving on (it includes a few sleep commands). I created a before_provision foreman hook python script.

broken image