我使用node.js编写了一个API。我已经在生产环境中部署了它。现在我使用forever.js运行程序(server.js),它工作正常
但我希望我的节点在系统启动时运行。
我尝试在\etc\init api.conf
中使用以下内容创建文件。
start on startup
exec forever start /home/testuser/server.js
但是当我重新启动我的系统时,上面没有运行。请帮我解决这个问题。
提前致谢。
编辑:
最后我试了一下:
# Source function library.
. /lib/lsb/init-functions
NODE_ENV="production"
PORT="2100"
APP_DIR="/home/testuser/API/"
NODE_APP="server.js"
CONFIG_DIR="$APP_DIR"
PID_DIR="$APP_DIR/pid"
PID_FILE="$PID_DIR/server.pid"
LOG_DIR="/home/testuser/APIlogs/"
LOG_FILE="$LOG_DIR/project-debug.log"
NODE_EXEC=$(which node)
pidFile="$PID_DIR/server.pid"
logFile="$LOG_DIR/project-debug.log"
sourceDir=/home/testuser/API
coffeeFile=server.js
scriptId=$sourceDir/$coffeeFile
start() {
echo "Starting $scriptId"
# This is found in the library referenced at the top of the script
start_daemon
# Start our CoffeeScript app through forever
# Notice that we change the PATH because on reboot
# the PATH does not include the path to node.
# Launching forever or coffee with a full path
# does not work unless we set the PATH.
cd $sourceDir
PATH=/usr/local/bin:$PATH
forever start /home/testuser/API/server.js
RETVAL=$?
}
restart() {
echo -n "Restarting $scriptId"
/usr/local/bin/forever restart $scriptId
RETVAL=$?
}
stop() {
echo -n "Shutting down $scriptId"
/usr/local/bin/forever stop $scriptId
RETVAL=$?
}
status() {
echo -n "Status $scriptId"
/usr/local/bin/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
当我尝试以下命令时:
/etc/init.d/API start
它运行正常。当我重新启动系统时,它会说“NO forever process”正在运行。