Skip to content

Instantly share code, notes, and snippets.

@zuk
Created February 6, 2014 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zuk/8852246 to your computer and use it in GitHub Desktop.
Save zuk/8852246 to your computer and use it in GitHub Desktop.
/etc/init.d/pm2 for CentOS
#!/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