Below is the upstart job for ubuntu for eg: create a file in /etc/init/test.conf and copy the below content to test.conf file, and change path to your app.js to yours,
#!upstart
description "node.js server"
author "kirthan shetty"
start on runlevel [2345] and started networking
stop on runlevel [!2345] or stopped networking
expect fork
script
export HOME="/root"
echo $$ > /var/run/yourprogram.pid
exec sudo -u root PORT=3004 /usr/bin/node /path to your app.js >> /var/log/yourprogram.sys.log 2>&1
end script
pre-start script
# Date format same as (new Date()).toISOString() for consistency
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/yourprogram.sys.log
end script
pre-stop script
rm /var/run/yourprogram.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/yourprogram.sys.log
end script
to start #service test start
to stop # service test stop
#!upstart
description "node.js server"
author "kirthan shetty"
start on runlevel [2345] and started networking
stop on runlevel [!2345] or stopped networking
expect fork
script
export HOME="/root"
echo $$ > /var/run/yourprogram.pid
exec sudo -u root PORT=3004 /usr/bin/node /path to your app.js >> /var/log/yourprogram.sys.log 2>&1
end script
pre-start script
# Date format same as (new Date()).toISOString() for consistency
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/yourprogram.sys.log
end script
pre-stop script
rm /var/run/yourprogram.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/yourprogram.sys.log
end script
to start #service test start
to stop # service test stop