I have a script i wrote that listens on mqtt. When certain code arrives to the mqtt server then an ngrok session is started like so:
subprocess.Popen(['/tmp/ngrok','http' ,'8080'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
the scrupt runs in a virtualenv and there for has a shell script to activate the virtual env and run it:
#!/bin/bash . ./venv/bin/activate python mqtt_listener.py
When running this script in my shell with & in the end the ngrok session opens and and is left open nicl untill i kill it myself. However when running in systemd using the following system file (user file) /home/myuser/.config/systemd/user/mqtt_listener.service
[Unit] Description=mqtt run service After=default.target [Service] Type=exec ExecStart=/home/myuser/mqtt_listener/run_mqtt_service.sh KillMode=process [Install] WantedBy=default.target
once the service gets the mqtt command i can see the the journal logs the service got my message and forked it's ngrok process, but then i can see
the service was "succesfully deactivated" and then restarts. the strange thing is that it always happens when i'm not logged in using ssh to the server, if i'm logged in the process will not die. Any idea what's i'm doing wrong ? the type=exec is due to the fact that the others just did not fit.I can't figure out why systemd considers my python service to be done and thus kills it after a grandchild fork (first fork is the run script, which apprently i can get rid of).