0

I run a system service with the following config my_script.service:

[Unit]
Description=My demo program.

[Service]
User=myname
ExecStart=/my_scripts/some_async_python_script.py
Restart=always
RestartSec=5s

[Install]
WantedBy=multi-user.target

Before running I would do this once: sudo systemctl daemon-reload and sudo systemctl enable my_script.service and then I would start like so: sudo systemctl start my_script.service

So far this work well.

The problem I have is that when I stop it with sudo systemctl stop my_script.service and then do htop I can see /my_scripts/some_async_python_script.py still running. I can see it has a parent process. When I kill the child process, it's dead (i.e. I don't need to kill the parent process).

My question is: Why is my service command still running even though I have stopped the service?

Newskooler
  • 211
  • 1
  • 3
  • 14
  • What is unusual and unexpected about this Python script? e.g. does it fork? How did it get a child process anyway? – Michael Hampton Jul 02 '21 at 16:22
  • The python script connects to a websocket and stream data asynchronously and I suspect that's where the issue is (but don't understand fully why). The script uses libraries such as `from aiostream import stream` and `import socket` and `from websockets import connect` Does that info help at all? – Newskooler Jul 02 '21 at 16:46
  • @MichaelHampton is there any more info on my end I can help with? – Newskooler Jul 13 '21 at 09:54
  • What is the status of the service after you tried to stop it? What was in the journal? – Michael Hampton Jul 13 '21 at 09:56
  • Before I `stop` it says `Active: active (running)` and after `stop` it says `Active: inactive (dead)` (as expected). The Main PID is indeed gone (when I do `htop`, I don't see it anywhere), however I do see another PID running which is the code inside my systemd service. That one I need to stop manually. I don't know why systemd does not stop it as well. – Newskooler Jul 13 '21 at 10:02

0 Answers0