Heads up! This post was written 11 years ago. Some information might be outdated or may have changed since then.
My server run Ubuntu's latest distribution which have a very decent version of upstart. Writing your own upstart scripts is very easy task, just copy and modify code bellow in
description "Your program"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /path/to/yourprogram.exe description "NodeJs Server"
author "yuks"
start on started mountall
stop on shutdown
respawn
respawn limit 99 5
script
export HOME="/root"
exec nodejs /projects/nodejs/public/app.js >> /var/log/node.log 2>&1
end script Main part of this .conf file is at
exec nodejs /projects/nodejs/public/app.js >> /var/log/node.log 2>&1 just modify the const express = require('express');
const app = express();
app.get('/', function(req, res) {
res.send('Hello World!');
});
app.listen(3000, function() {
console.log('Server is running on port 3000');
}); with your nodejs app. Re/Start of this daemon is ridiculusly easy:
start yourprogram
stop yourprogram
restart yourprogram and of course this will start automaticly on boot time. Also we can view the status of daemon with this simple command: user@nodejs:~# initctl status node-app
node-app start/running, process 339 More information about NodeJs can be found at http://nodejs.org/#about