Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This is my upstart file /etc/init/myapp.conf:

description "Example of starting Node with Upstart and Forever"

start on filesystem or runlevel [2345]
stop on runlevel [06]

expect fork

console output

setuid lwood

env HOME=/home/lwood
env LOG="/home/lwood/myapp/applog.log"    

script
  cd $HOME
  exec forever -a -l $LOG \
       start /home/lwood/myapp/app.js
end script

pre-stop script
  cd $HOME
  exec forever stop /home/lwood/myapp/app.js >> $LOG
end script

Do you know why sudo restart myapp is only stopping the service? It does not start the service after stopping it. So it has the same effect as sudo stop myapp.

Doing sudo stop myapp and then sudo start myapp works fine though. Wondering why restarting behaves different.

I'm on Ubuntu 12.04.

share|improve this question

1 Answer 1

There is a bug in upstart. It still exists in Ubuntu Raring 13.04, but I haven't tested Saucy or later yet.

Basically, pre-stop should be avoided. It causes undefined state changes on restart. If you're using it to trigger the shutdown of a daemon, as in your case, it will just stop everything. In a more classical usage, even specifying a pre-stop script will prevent your main process from restarting (as demonstrated in the bug report).

The behavior of "on stopping" jobs seems to be unaffected, so one solution is to create a myapp-stop.conf job that is triggered "on stopping myapp". The only apparent disadvantage is that it's more difficult to know when all other potentially "on stopping myapp" jobs are completed.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.