我已经设置pm2来运行node.js应用程序,我可以成功启动它,它会在重启时恢复.
但是,pm2守护进程是以root身份运行的,这使我认为我的所有节点脚本也以root身份运行?即使我将它们添加为系统中的常规用户.日志文件和内容在用户主目录/ //.pm2/logs中创建,但日志由root拥有.
当我调用pm2启动(处理init.d脚本的安装等)时,它会创建/etc/init.d/pm2-init.sh,如下所示:
#!/bin/bash
# chkconfig: 2345 98 02
#
# description: PM2 next gen process manager for Node.js
# processname: pm2
#
### BEGIN INIT INFO
# Provides: pm2
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: PM2 init script
# Description: PM2 is the next gen process manager for Node.js
### END INIT INFO
NAME=pm2
PM2=/usr/local/lib/node_modules/pm2/bin/pm2
NODE=/usr/local/bin/node
export HOME="/root"
start() {
echo "Starting $NAME"
$NODE $PM2 stopAll
$NODE $PM2 resurrect
}
stop() {
$NODE $PM2 dump
$NODE $PM2 stopAll
}
restart() {
echo "Restarting $NAME"
stop
start
}
status() {
echo "Status for $NAME:"
$NODE $PM2 list
RETVAL=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit $RETVAL
当我转储进程时(这是复活进程时将使用的进程),我看到提到用户“USER”:“pi”但我不认为它实际上是以用户pi运行的.
有什么想法吗?