Why does upstart keep respawning my process?

passy

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?

slangasek

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Upstart not respawning Sidekiq daemon

From Dev

Why does my node app process keep getting stopped when I use forever?

From Dev

Why does ld's KEEP() does not keep my symbols?

From Dev

Why does .lesshst keep showing up in my ~

From Dev

Why does my umask keep resetting to 000?

From Dev

Why does my image keep repeating itself?

From Dev

Why does my CPU usage keep spiking?

From Dev

Why does my CPU usage keep spiking?

From Dev

Why does my computer keep switching on?

From Dev

Why does my umask keep resetting to 000?

From Dev

Why does my laptop keep shutting down?

From Dev

Why does my ActionListener keep repeating?

From Dev

Why does my accordion list keep closing?

From Dev

Why does my monitor keep cutting out?

From Dev

Why does the time on my laptop keep changing?

From Dev

Why does my code keep throwing a KeyError?

From Dev

Why does my vba code keep freezing?

From Dev

Why does my batch file keep on closing?

From Dev

Why does my script work when started from console but does not work when started via upstart?

From Dev

why does xPage process my Comments

From Dev

Why does upstart fail to start my juju service with Unknown job: juju-ubuntu-0?

From Dev

Why does upstart fail to start my juju service with Unknown job: juju-ubuntu-0?

From Dev

Why does my send button keep overlapping my edit text?

From Dev

Why does my send button keep overlapping my edit text?

From Dev

Why does my text keep moving my image down?

From Dev

Why does my client keep recieving b'' and my server crashes

From Dev

Upstart script exported by Foreman not working properly, respawning too fast

From Dev

"respawning too fast, stopped". How to make UPSTART disable for 5 mins?

From Dev

Why does my Erlang boot script work from console but does not work when run from init system (sysvinit, upstart, systemd)?

Related Related

  1. 1

    Upstart not respawning Sidekiq daemon

  2. 2

    Why does my node app process keep getting stopped when I use forever?

  3. 3

    Why does ld's KEEP() does not keep my symbols?

  4. 4

    Why does .lesshst keep showing up in my ~

  5. 5

    Why does my umask keep resetting to 000?

  6. 6

    Why does my image keep repeating itself?

  7. 7

    Why does my CPU usage keep spiking?

  8. 8

    Why does my CPU usage keep spiking?

  9. 9

    Why does my computer keep switching on?

  10. 10

    Why does my umask keep resetting to 000?

  11. 11

    Why does my laptop keep shutting down?

  12. 12

    Why does my ActionListener keep repeating?

  13. 13

    Why does my accordion list keep closing?

  14. 14

    Why does my monitor keep cutting out?

  15. 15

    Why does the time on my laptop keep changing?

  16. 16

    Why does my code keep throwing a KeyError?

  17. 17

    Why does my vba code keep freezing?

  18. 18

    Why does my batch file keep on closing?

  19. 19

    Why does my script work when started from console but does not work when started via upstart?

  20. 20

    why does xPage process my Comments

  21. 21

    Why does upstart fail to start my juju service with Unknown job: juju-ubuntu-0?

  22. 22

    Why does upstart fail to start my juju service with Unknown job: juju-ubuntu-0?

  23. 23

    Why does my send button keep overlapping my edit text?

  24. 24

    Why does my send button keep overlapping my edit text?

  25. 25

    Why does my text keep moving my image down?

  26. 26

    Why does my client keep recieving b'' and my server crashes

  27. 27

    Upstart script exported by Foreman not working properly, respawning too fast

  28. 28

    "respawning too fast, stopped". How to make UPSTART disable for 5 mins?

  29. 29

    Why does my Erlang boot script work from console but does not work when run from init system (sysvinit, upstart, systemd)?

HotTag

Archive