Node.js Apply daemon Manager Forever Install and use instances _node.js

Source: Internet
Author: User
Tags node server

It is not possible to manage a remote site directly through the node command, which makes it impossible to keep the site running. We use forever to solve this problem, it can be nodejs application of the way the daemon process, we can also set the Nodejs application to start with the system to run automatically.

First, install Forever:

Copy Code code as follows:

NPM Install FOREVER-GD

So forever is installed, we can run the Forever command directly:
Copy Code code as follows:

Forever--help
Forever Start App.js
Forever Stop App.js

The above command looks at the forever Help file first, then runs App.js, and then stops app.js. We want forever to run automatically, and first create a file node in the/ETC/INIT.D directory, which reads as follows:
Copy Code code as follows:

#!/bin/bash
#
# node Start up node Server daemon
#
# chkconfig:345 85 15
# Description:forever for Node.js
#
Path=/home/node/0.8.9/bin
Deamon=/home/ftp/1520/weizt-20120918-tkx/weizt.com/app.js
Log=/home/hosts_log
Pid=/tmp/forever.pid
Case "$" in
Start
Forever start-l $LOG/forever.log-o $LOG/forever_out.log-e $LOG/forever_err.log--pidfile $PID-a $DEAMON

Stop
Forever Stop--pidfile $PID $DEAMON

StopAll)
Forever StopAll--pidfile $PID

Restartall)
Forever Restartall--pidfile $PID

Reload|restart)
Forever restart-l $LOG/forever.log-o $LOG/forever_out.log-e $LOG/forever_err.log--pidfile $PID-a $DEAMON

List
Forever List

*)
echo "Usage:/etc.init.d/node {start|stop|restart|reload|stopall|restartall|list}"
Exit 1

Esac
Exit 0

The above code is my local virtual machine configuration, according to the actual situation to modify the relevant parameters, mainly Deamon path parameters, give the file executable permissions, and run Chkconfig add automatic run:
Copy Code code as follows:

chmod 755/etc/init.d/node
Chkconfig/etc/init.d/node on

Reboot restart the system, through the browser to enter the site can be found, the NODEJS has been able to automatically run, the rest of the work is to study Nodejs, Express and Angularjs, to do a really belong to their own application!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.