Reputation: 1304
I am new to linux so I am wondering how can I make service run forever? and automatically restart if it crashes or stops?
I am running Node.js + Socket.io as a chat server.
Upvotes: 2
Views: 6315
Reputation: 31
For start you server you can use: monit
, forever
, upstart
or systemd
.
For Forever:
Start a process:
forever start example.js
Stop the process
forever stop example.js
Upvotes: 0
Reputation: 12399
You have 2 main options for node.js :
Option 1 : node-forever
npm install forever -g
then you run your script by typing : forever start myscript.js
Option 2 : pm2
npm install pm2 -g
then you run your script by typing : pm2 start myscript.js
The main difference is that pm2 has zero downtime, a web interface, console monitor and a built-in load balancer. The web interface itself has proved an invaluable bonus for many of my projects.
I would recommend forever in development mode, and pm2 in production, the reason being that pm2 sometimes keeps the port in use when you kill it, so it's a bit annoying in dev when you restart all the time. Otherwise pm2 has a lot more features and has never disappointed me, I use it all the time.
Upvotes: 5
Reputation: 2014
you can use Forever NPM this is easy to use, i was also new but tried this my work gone easy :)
Upvotes: 0
Reputation: 1454
Take a look at Monit It's a standard open source app for monitoring processes and restarting them if they fail.
Upvotes: 0