I run a web site that uses Node.JS on Ubuntu Server (14.04 LTS). After rebooting the machine, my current workflow is to manually start the server manually by running the command
$ forever start app.js
I'm now trying to automate this process with Upstart. I have used chkconfig on RHEL before, but I am new to Upstart. I wrote the following script and saved it in /etc/init/myapp.conf.
#!upstart description "Start the node process with Upstart" start on startup stop on shutdown expect fork env APP_DIR="/path/to/app" env NODE_BIN="/usr/local/bin" env HOME_DIR="/home/admin" script date echo "Starting" su admin cd $APP_DIR PATH=$NODE_BIN:$PATH HOME=$HOME_DIR echo "Running forever start" forever start app.js end script pre-stop script date echo "Stopping" su admin cd $APP_DIR PATH=$NODE_BIN:$PATH HOME=$HOME_DIR echo "Running forever stop" forever stop app.js end script
However, the script does not seem to work. When I run
sudo start myapp or
sudo stop myapp, the console just hangs.
I would like Upstart to emulate as closely as possible to what would happen if I just signed in to the computer upon reboot and ran
forever start app.js, including the user running the process, the default log file locations, and so on.