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:
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!