-
-
Save zuk/8852246 to your computer and use it in GitHub Desktop.
/etc/init.d/pm2 for CentOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: | |
# 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 | |
USER=pm2 | |
export HOME="/var/run/pm2" | |
super() { | |
su -l $USER -c "$1 $2 $3 $4" | |
} | |
start() { | |
echo "Starting $NAME" | |
super $NODE $PM2 stop all | |
super $NODE $PM2 resurrect | |
} | |
stop() { | |
super $NODE $PM2 dump | |
super $NODE $PM2 stop all | |
} | |
restart() { | |
echo "Restarting $NAME" | |
super stop | |
echo "Waiting 10 seconds for shutdown..." | |
wait 10 | |
super start | |
} | |
status() { | |
echo "Status for $NAME:" | |
super $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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment