Node.js Forever upstart 脚本停止挂起

Node.js Forever upstart 脚本停止挂起

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

我尝试bill在启动时以我的身份运行该脚本。并能够重新启动和停止该脚本。

我正在使用 npm 模块forever来实现这一点。我发现,当我发出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

答案1

使用

setuid bill

作为 Upstart 节(只需将这些词放在文件的新行中)并删除内容susu将分叉一个新进程,并且 Upstart 将不会跟踪正确的 PID,因此您不需要使用su

相关内容