How to make a 'service' running my Node.js application on Ubuntu server
Many people use forever https://github.com/nodejitsu/forever , which has become pretty much industry standard.
If you are on Ubuntu, you can also use init scripts ( google 'ubuntu upstart' ), that will do much the same thing, and are guaranteed to if the server ever gets restarted.
Here is my upstart script for example https://gist.github.com/qbert65536/5271721 .
It gets run when the server starts, you also control them with
start myapp, stop myapp, restart myapp , where myapp.conf is the name of the upstart script.
Comments
-
Shuping almost 2 years
I don't know what I should call it on Ubuntu Server, but most time I work on Windows it is called a service for running an application on the background.
I build my web server based on Node.js, so to deploy it on Ubuntu sever I need a 'service' for running Node.js, I want the 'service':
- Running on the background
- Has the ability to start Node.js automatically if my web server crashes Node.js
Normally, I run a Node.js application by opening a terminal an run the js file. But from my understanding this is more for testing purpose because there is no guarantee from the terminal to start Node.js after a fail.
-
RobM over 8 yearsThanks for the sample upstart script - I always assumed upstart scripts would be a pain to write, and would never have thought to look into it!