1 进入 /etc/init.d, 新建文件 nodeserver(名字可以随便取)
cd /etc/init.d
touch nodeserver
2 编辑nodeserver
#!/bin/sh
# chkconfig: 2345 85 15
# description: Startup script for nodeserver.
# exit on first error
set -e
# points to the root for forever config
export "FOREVER_ROOT=/root/.forever"
#LOG=/data/nodeserver/log
PID=/data/nodeserver/pid
starts=(
"forever /var/www/html/drunk start drunk.js"
"forever /var/www/html/wx start wxapi.js"
)
# commands to run on "stop" (new line per command)
stops=(
"forever stop --pidFile $PID /var/www/html/drunk/drunk.js"
"forever stop --pidFile $PID /var/www/html/wx/wxapi.js"
)
# start function
do_start(){
for i in "${starts[@]}"
do
$i
done
}
# stop function
do_stop(){
for i in "${stops[@]}"
do
$i
done
}
# Decide what command is being called
case "$1" in
start)
echo "Starting nodeserver..."
do_start
echo "done."
;;
stop)
echo "Stoping nodeserver..."
do_stop
echo "done."
;;
restart)
echo "Restarting nodeserver..."
do_stop
do_start
echo "done."
;;
*)
echo "Usage: nodeserver {start|stop|restart}" >&2
exit 3
;;
esac
exit 0
设置nodeserver执行权限
3 加入开机项:
chkconfig --add nodeserver
4 nodeserver命令
service nodeserver start
service nodeserver stop
service nodeserver restart