I'm using Ubuntu Sever 12.04. I have a nodejs application which I want to run like so:
NODE_ENV=production PORT=3001 APP_PATH=/var/www/myapp forever -a -l /var/www/myapp/forever.log -o /var/www/myapp/out.log -e /var/www/myapp/err.log /var/www/myapp/app.js
I want to run it at system startup and do 'forever stopall' at system shutdown. I've read that the preferred way to do that is using upstart scripts. That's what I tried:
description "Upstart script"
start on startup
stop on shutdown
expect fork
env MYAPP_PATH="/var/www/myapp"
script
NODE_ENV=production PORT=3001 APP_PATH=$MYAPP_PATH exec forever -a -l $MYAPP_PATH/forever.log -o $MYAPP_PATH/out.log -e $MYAPP_PATH/err.log $MYAPP_PATH/app.js
end script
pre-stop script
exec forever stop $MYAPP_PATH/app.js >> $LOG
end script
It hangs when I run it, and then it says that job is already running (when it is actually not).
Any advice how to do this properly is appreciated. Thanks!