我永远配置为在启动时运行我的 node.js 服务器。使用这个 scipt。它工作正常。并永远保持服务器运行。但是,当我运行永久列表时,我在这里看不到我的服务器!我知道它正在运行,但它从未在此列表中。看起来系统正在运行两个永远的实例。
root@ddd [/etc/init.d]# chkconfig --list |grep node1
node1 0:off 1:off 2:on 3:on 4:on 5:on 6:off
这是脚本:/etc/init.d/node1
NAME=node1
NODE_BIN_DIR=/usr/local/bin
NODE_PATH=/usr/local/lib/node_modules
APPLICATION_DIRECTORY=/home/user1/www
APPLICATION_START=node1.js
PIDFILE=/var/run/node1.pid
LOGFILE=/var/log/node1.log
PATH=$NODE_BIN_DIR:$PATH
export NODE_PATH=$NODE_PATH
start() {
echo "Starting $NAME"
forever --pidFile $PIDFILE --sourceDir $APPLICATION_DIRECTORY \
-a -l $LOGFILE --minUptime 5000 --spinSleepTime 2000 \
start $APPLICATION_START &
RETVAL=$?
}
stop() {
if [ -f $PIDFILE ]; then
echo "Shutting down $NAME"
forever stop $APPLICATION_START
rm -f $PIDFILE
RETVAL=$?
else
echo "$NAME is not running."
RETVAL=0
fi
}
restart() {
echo "Restarting $NAME"
stop
start
}
status() {
echo "Status for $NAME:"
forever list
RETVAL=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit $RETVAL