pm2/lib/scripts/pm2-init.sh
abluchet 0996f7bccb Startup refractor
- replaced all instances of `sudo` by native `su`
- startup scripts are called with su -c "cmd"
- improved code (less repetitions)
- user is added to the init script but isn't the one that fix permission and put the upstart script
2014-07-04 10:01:38 +02:00

83 lines
1.3 KiB
Bash

#!/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=%PM2_PATH%
USER=%USER%
export PATH=$PATH:%NODE_PATH%
export PM2_HOME="%HOME_PATH%"
super() {
su - $USER -c "PATH=$PATH; $*"
}
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