Deploy Nodejs app in Centos 6.2
Many options to deploy nodejs apps, but after some research I found the solution that works and yet simple. First I tried Forever, it works perfectly until you need your app to be started during boot, i put a line in the /etc/rc.d/rc.local, this might or might not work, it still confuses me up to now, why there are times working and times failed.
next is the Upstart and Monit, upstart has made the writing of starting up script as simple as autoexec.bat in the DOS time, and monit will do the checking of your app to be sure it is working all the time.
Then again, I found out, my need is simple, 1. app should be started during the boot, and 2. restarted if it crashes (that happens in nodejs app), and upstart alone is enough for the two jobs.
Centos 6.2 comes with upstart installed, so what you need to do is create a text file in /etc/init, say, myapp.conf:
#!upstart description "testjs.js " author "sample" start on runlevel  stop on shutdown respawn script export HOME="/root" echo $$ > /var/run/testjs.pid exec /usr/local/bin/node /root/test.js >> /var/log/testjs.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/testjs.log end script pre-stop script rm /var/run/testjs.pid echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/testjs.log end script
once it is finished, you can do:
and app will be started during booting, you don’t need any other utility in Centos 6.2 to start and keep your app running. I found Centos requires start on runlevel , other options seem not working.
Some useful links as follow: