Run while true in systemd script
You need to let systemd work for you. Let it handle the forking at the start and the killing of the process. Eg replace your service part by
[Service]
Type=simple
ExecStart=/usr/local/bin/somescript
PIDFile=/tmp/somescript.pid
then you can use systemctl start
, status
and stop
. You must remember that the lines in systemd are NOT interpreted by the shell, so for example your &;
is merely passed as another parameter of 2 characters to your script.