Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
23
rated 0 times [  23] [ 0]  / answers: 1 / hits: 19989  / 2 Years ago, sun, august 28, 2022, 11:20:38

I wrote an upstart script to launch a daemon inside a tmux session. It works well and respawns the process if it dies unexpectedly, but I can't seem to stop it manually.



The job (called bukkit) looks like this:



start on filesystem
stop on runlevel [!2345]

respawn
respawn limit 5 30

chdir /home/minecraft/bukkit

expect daemon
kill timeout 30

pre-start script
test -x /home/minecraft/bukkit/craftbukkit-0.0.1-SNAPSHOT.jar || { stop; exit 0; }
end script

pre-stop script
tmux send -t bukkit "stop"
tmux send -t bukkit "Enter"
sleep 10 # Wait for server to shut down properly
end script

exec tmux new-session -d -s minecraft -n bukkit "sudo -u minecraft -- /home/minecraft/java/jre1.6.0_27/bin/java -Xincgc -Xmx1G -jar /home/minecraft/bukkit/craftbukkit-0.0.1-SNAPSHOT.jar"


When I issue a stop bukkit it freezes for ~10 seconds (the sleep timer, I guess) and prints bukkit start/running, process 2391. When I set upstart to debug, I found these relevant lines in the log:



Sep 21 19:14:59 cheftest init: bukkit goal changed from start to stop
Sep 21 19:14:59 cheftest init: bukkit main process (2499) exited normally
Sep 21 19:14:59 cheftest init: bukkit main process ended, respawning
Sep 21 19:14:59 cheftest init: bukkit goal changed from stop to respawn


Why does upstart keep respawning my process when it is supposed to stop it?


More From » server

 Answers
7

The difficulty here is the combination of 'respawn' with a pre-stop script that tells the process to stop. From init(5):




   respawn
A service or task with this stanza will be automatically started
if it should stop abnormally. All reasons for a service stopping,
except the stop(8) command itself, are considered abnormal. Tasks
may exit with a zero exit status to prevent being respawned.



The documentation is a little unclear on the point of whether exiting with a zero exit status should cause a respawn. However, fundamentally you've found an upstart bug because the main process ending when the goal is 'stop' should not result in a change to 'respawn'.



To work around this bug, you should be able to use "normal exit" to tell upstart that this is a normal way to stop the job and that it should not respawn.




  normal exit STATUS|SIGNAL...
Additional exit statuses or even signals may be added, if the
job process terminates with any of these it will not be considered
to have failed and will not be respawned.

normal exit 0 1 TERM HUP



Note that in general, it would be more robust to kill the process with a signal (specifying "kill signal N" if necessary) instead of with a pre-stop process that issues commands; but of course this is not always possible if the service doesn't support clean shutdown upon receipt of a signal.


[#43407] Monday, August 29, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
igeonlothe

Total Points: 370
Total Questions: 121
Total Answers: 114

Location: United States Minor Outlying Island
Member since Fri, Feb 5, 2021
3 Years ago
igeonlothe questions
Wed, May 31, 23, 02:34, 1 Year ago
Sat, Mar 12, 22, 17:13, 2 Years ago
Tue, Aug 31, 21, 09:46, 3 Years ago
;