How to run your node.js based platform into production. And have it run permanently in the background as a service (even after a reboot).
To achieve this were are going to use an application called supervisor
http://supervisord.org/ which comes with most distro's. in Ubuntu if it's not installed already, then install it using:
apt-get install supervisor
check the version using:
supervisorctl version > 3.0a8
At time of writing my version is: 3.0a8 which is already out of date as the latest is actually 3.1.3, but for now I don't care about that.
We then need to create a config file for our Node App (lets assume it's called MyNodeApp and it's being run from a folder: /var/www/mynodeapp/)
create the config file:
and paste the following into it (then save):
[program:mynodeapp] command = node /var/www/mynodeapp/index.js directory = /var/www/mynodeapp user = www-data autostart = true autorestart = true stdout_logfile = /var/log/supervisor/mynodeapp.log stderr_logfile = /var/log/supervisor/mynodeapp_err.log environment = NODE_ENV="production"
Make supervisor rescan the available configs:
Start the App using Supervisor:
supervisorctl start mynodeapp
To stop your App:
supervisorctl stop mynodeapp
keep an eye on what is going on by tailing the log files.
tail -f /var/log/supervisor/mynodeapp.log