Node.js永远的新贵脚本停止挂起

我正在使用Ubuntu 14.04,Node.js安装到.nvm,并且我的主目录下的项目方向。

我正在试图在启动时运行脚本。 并有能力重新启动并停止脚本。

forever使用npm模块来完成这个任务。 我发现的一件事是,当我发出sudo stop myapp时脚本简单地挂起

在/etc/init/myapp.conf中

 #!upstart description "My Node app" start on filesystem and started networking stop on shutdown # You need this so Upstart reports the proper process ID of Node and not Forever. expect fork # Monitor Forever respawn respawn limit 5 30 # Node paths (change to suit your installation) # The full path to the directory containing the node and forever binaries. env NODE_BIN_DIR="/home/bill/.nvm/v0.10.30/bin" # Set the NODE_PATH to the Node.js main node_modules directory env NODE_PATH="/home/bill/.nvm/v0.10.30/lib/node_modules" # The main file that starts our app (usually called server.js or app.js) env APPLICATION_PATH="/home/bill/project/bin/www" # Process ID file path env PIDFILE="~/bill.pid" # Log file path env LOG="~/bill.log" # Forever settings to prevent the application spinning up constantly if it fails on launch. env MIN_UPTIME="5000" env SPIN_SLEEP_TIME="2000" script # Add our Node stuff to the main path PATH=$NODE_BIN_DIR:$PATH exec su -c "forever --pidFile $PIDFILE -a -l $LOG --minUptime $MIN_UPTIME --spinSleepTime $SPIN_SLEEP_TIME start $APPLICATION_PATH" - bill end script pre-stop script PATH=$NODE_BIN_DIR:$PATH exec su -c "forever stop $APPLICATION_PATH" - bill end script 

使用

 setuid bill 

作为一个Upstart节(只是把这些文字在文件中的新行),并删除su东西。 su会分叉一个新的进程,而Upstart不会跟踪正确的PID,所以你不需要使用su