设置我的服务器的NodeJS成功,我用它的Ubuntu 15.04服务器上,我的问题是,我希望我的节点应用程序继续运行在服务器重新启动,所以我尝试pm2
,forever
和crontab
但他们都没有为我工作,重新启动后,我需要手动启动节点应用程序。PM2启动不起作用
我试图pm2
如下:
pm2 startup ubuntu
pm2 start appname
pm2 save
的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: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# 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=/home/bashar/.nvm/versions/node/v4.1.1/lib/node_modules/pm2/bin/pm2
USER=bashar
export PATH=/home/bashar/.nvm/versions/node/v4.1.1/bin:$PATH
export PM2_HOME="/home/bashar/.pm2"
get_user_shell() {
local shell=$(getent passwd ${1:-`whoami`} | cut -d: -f7 | sed -e 's/[[:space:]]*$//')
if [[ $shell == *"/sbin/nologin" ]] || [[ $shell == "/bin/false" ]] || [[ -z "$shell" ]];
then
shell="/bin/bash"
fi
echo "$shell"
}
super() {
local shell=$(get_user_shell $USER)
su - $USER -s $shell -c "PATH=$PATH; PM2_HOME=$PM2_HOME $*"
}
start() {
echo "Starting $NAME"
export PM2_HOME
super $PM2 resurrect
}
stop() {
super $PM2 dump
super $PM2 delete all
super $PM2 kill
}
restart() {
echo "Restarting $NAME"
stop
start
}
reload() {
echo "Reloading $NAME"
super $PM2 reload all
}
status() {
echo "Status for $NAME:"
super $PM2 list
RETVAL=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
reload)
reload
;;
force-reload)
reload
;;
*)
echo "Usage: {start|stop|status|restart|reload|force-reload}"
exit 1
;;
esac
exit $RETVAL
这并没有工作,所以我试图用crontab
如下: 首先,我创建了一个脚本并命名为starter.sh
#!/bin/bash
pm2 start /home/bashar/www/node/server.js
开然后编辑crontab
:
crontab -e
@reboot /home/bashar/www/node/server.js
而且上面的方法没有启动我的服务器上重新启动应用程序。
请指点,
我已经设法让我的系统正常启动 - http://stackoverflow.com/questions/32769302/ubuntu-14-04-pm2-startup-not-starting-after-reboot - 虽然我不知道如果Ubuntu 15.04完全一样 – Max
没有,没有与我一起工作,你没有做其他建议的步骤,以启动pm2工作。 pm2的版本已经0.15.7 –