Score:0

When I "stop" a system process, the "ExecStart" command process does not stop

it flag

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?

Michael Hampton avatar
cz flag
What is unusual and unexpected about this Python script? e.g. does it fork? How did it get a child process anyway?
Newskooler avatar
it flag
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 avatar
it flag
@MichaelHampton is there any more info on my end I can help with?
Michael Hampton avatar
cz flag
What is the status of the service after you tried to stop it? What was in the journal?
Newskooler avatar
it flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.