New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pm2 startup not working after updating Node #2006
Comments
Hello, Yes it may come from an update of Node.js. |
Hi @Unitech, yes I'm using nvm. This is the content of #!/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=/usr/local/nvm/versions/node/v5.7.1/lib/node_modules/pm2/bin/pm2
USER=admin
DEFAULT=/etc/default/$NAME
export PATH=/usr/local/nvm/versions/node/v5.7.1/bin:$PATH
export PM2_HOME="/home/admin/.pm2"
# The following variables can be overwritten in $DEFAULT
# maximum number of open files
MAX_OPEN_FILES=
# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
. "$DEFAULT"
fi
# set maximum open files if set
if [ -n "$MAX_OPEN_FILES" ]; then
ulimit -n $MAX_OPEN_FILES
fi
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"
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 Any idea how the issue could be fixed? Thanks! Cheers |
Please review it by yourself depending on your Node.js version, PM2 paths and so on, thank you |
Yes, the Node executable path and the pm2 package path change each time Node is updated through nvm. Here's an example of how paths respectively change:
Currently this breaks the pm2 daemon, which is extremely undesirable. In fact, if one sets up pm2 to automatically start on reboot, this behaviour is expected to hold true after updating Node. Imho the daemon script generated by pm2 could possibly detect the current Node version path at startup instead of storing a constant string, and this should be enough to fix the problem. Now, if I understand correctly it depends on how Node is installed on the system. We could start dividing in two big families:
Let's consider the nvm scenario first. As long as we can know where For example: source /usr/local/nvm/nvm.sh # (not sure yet what is the best way to localize nvm.sh)
NODE_PATH=$NVM_BIN/node
PM2_PATH=$NVM_BIN/../lib/node_modules/pm2/bin/pm2 If Node is not installed through nvm instead, other methods could be found. Before digging further, what do you think about the general approach and feasibility? Cheers! |
You need to rerun pm2 startup command when the node.js version changes |
Can you add this bit of info to the docs? If you like I can also send a PR. Thx! |
@pensierinmusica It would be perfect if you can make a PR for this, we may update the docs ourselves but after being published on the main branch (end of december i guess) |
Hi,
I've pm2 set up with a few processes, that have been saved, then ran
pm2 startup ubuntu
.It was all working fine: on every server reboot pm2 would restart the processes.
Recently though I updated Node and pm2.
Then, I noticed that the pm2 was not starting up anymore on reboot. I'm not sure if this is due to updating the Node version, or pm2 itself.
In either case I think this is highly undesirable, and it should be fixed. If I set up pm2 to automatically start on reboot, I expect this behaviour to hold true after updating Node or pm2.
Could you please check? Thanks!
p.s. Imho a good suspect for this bug is that the Node executable path changes after a Node update
The text was updated successfully, but these errors were encountered: