本文共 1393 字,大约阅读时间需要 4 分钟。
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 errorset -e# points to the root for forever configexport "FOREVER_ROOT=/root/.forever"#LOG=/data/nodeserver/logPID=/data/nodeserver/pidstarts=( "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 functiondo_start(){ for i in "${starts[@]}" do $i done}# stop functiondo_stop(){ for i in "${stops[@]}" do $i done}# Decide what command is being calledcase "$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 ;;esacexit 0
设置nodeserver执行权限
3 加入开机项:
chkconfig --add nodeserver
4 nodeserver命令
service nodeserver start
service nodeserver stop
service nodeserver restart
转载于:https://blog.51cto.com/13968450/2174747