Copy Code code as follows:
#!/bin/bash
### BEGIN INIT INFO
# Provides:xiyoulib
# Required-start: $all
# required-stop: $all
# Default-start:2 3 4 5
# default-stop:0 1 6
# Short-description:start Daemon at the boot time
# Description:enable service provided by Daemon.
### End INIT INFO
# chkconfig:345 88 08
# Description:forever for Node.js
deamon=/home/wwwroot/default/im/chat.js #这里需要填写你自己的Node项目的启动脚本文件
log=/home/wwwroot/default/im/log/log #可选, log file directory
pid=/home/wwwroot/default/im/log/pid #必填内容, used to record the forever process number
export path= $PATH:/usr/local/bin #在这里指定一下Node的可执行程序安装目录, mine is/usr/local/bin
export node_path= $NODE _path:/usr/local/lib/node_modules #这里是Node类库的路径
#往下的内容就不用修改了
Node=node
Forever=forever
case "$" in
start)
$forever start-l $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--pidfile $PID-a $DEAMON
;;
list)
$forever List
;;
*)
echo "Usage:/etc.init.d/node {start|stop|restart|reload|stopall|restartall|list}"
Exit 1
;;
Esac
Copy Code code as follows:
chmod 755/etc/init.d/node
Chkconfig/etc/init.d/node on