1.安装nodejs和forever npm install forever -g
2.制作自己nodejs的自启动文件,在此为express框架,放在/etc/init.d/***
确定网站所在文件夹(/root/ImageServer),以及执行文件(bin/www)
#!/bin/bash## node Start up node server daemon## chkconfig: 345 85 15# description: Forever for Node.js#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binLOG=/work/server/hosts_logPID=/work/server/forever.pid
function start_app {cd /root/ImageServer; forever start "bin/www" -l $LOG/forever.log -o $LOG/forever_out.log -e $LOG/forever_err.log --pidFile $PID}function stop_app { cd /root/ImageServer; forever stop "bin/www"}
case $1 in start) start_app ;; stop) stop_app ;; restart) stop_app start_app ;; *) echo "usage: clearstonecc {start|stop}" ;;esacexit 0
3.确认文件属性 sudo chmod 755 /etc/init.d/***
4.启动服务
sudo chkconfig -add ***
chkconfig *** on
5.控制服务
service *** start
service *** stop
service *** restart
转载于:https://www.cnblogs.com/lovesumer/p/5506129.html