It is not possible to manage remote sites directly through the node command, which does not guarantee the sustainable operation of the site. We use forever to solve this problem, it can be nodejs to apply the way the future daemon, we can also set the Nodejs app to run automatically with the system boot.
First, install Forever:
NPM Install FOREVER-GD
So the forever is installed, we can run the Forever command directly:
Forever--helpforever start app.jsforever stop app.js
The above command first looks at the forever Help file, then runs App.js, and then stops app.js. We want to let forever run automatically, first create a file node in the/ETC/INIT.D directory, the contents are as follows:
#!/bin/bash## node Start up node server daemon## chkconfig:345 85 15# Description:forever forNode.js#path=/home/node/0.8.9/Bindeamon=/home/ftp/1520/weizt-20120918-tkx/weizt.com/App.jslog=/home/Hosts_logpid=/tmp/Forever.pid Case"$"inchstart) forever start-L $LOG/forever.log-o $LOG/forever_out.log-e $LOG/forever_err.log--pidfile $PID-a $DEAMONstop) 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 $DEAMONlist) Forever list*) echo"Usage:/etc.init.d/node {start|stop|restart|reload|stopall|restartall|list}"Exit1Esacexit0
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 Autorun:
chmod 755/etc/init.d/nodechkconfig/etc/init.d/node on
Reboot restart system, through the browser to enter the site can be found, the NODEJS has been able to run automatically, the rest of the work is to study Nodejs, Express and Angularjs, do a really own application!
node. JS deployed to the server after the daemon manager forever