This Content is from Stack Overflow. Question asked by mxwQuestion
I have a script that I would like to run as service on my Linux machine, let’s call it
my_script.sh. It is executable and can be run over
I also have script that kills
my_script.sh, let’s call it
kill_my_scprit.sh. The contents of
#!/bin/bash sudo kill -SIGINT $(pgrep my_script)
In essence, this should mimic
This works perfectly fine if I run the scripts from a terminal, i.e. in ttyX I run
./path/to/my_scrit.sh to start it and in ttyY
./path/to/kill_my_scrit.sh to initiate the shut down sequence of
As mentioned before, the goal is to run this as deamon, so I created
[Unit] .... [Service] Type=simple User=root WorkingDirectory=/path/to/dir/ ExecStart=/path/to/my_script.sh ExecStop=/path/to/kill_my_script.sh Restart=on-failure [Install] ...
sudo systemctl start my_script.service starts the script as expected, but using
sudo systemctl stop my_script.service starts the shutdown sequence for
my_script.sh, but doesn’t let it finish… Am I missing something? The shutdown sequence takes roughly 10sec…
This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.
This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.