-
-
Save centminmod/7392908 to your computer and use it in GitHub Desktop.
SHELL: ghost1 CentOS init.d script
This file contains 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: ghost1 | |
# | |
### BEGIN INIT INFO | |
# Provides: ghost1 | |
# Required-Start: | |
# Required-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
### END INIT INFO | |
########################################### | |
if [ -f /proc/user_beancounters ]; then | |
ulimit -s 256 | |
fi | |
########################################### | |
PM2=/usr/local/lib/node_modules/pm2/bin/pm2 | |
NODE=/usr/local/bin/node | |
USER=root | |
export NODE_ENV=production | |
########################################### | |
# edit NAME to unique name for each specific Ghost instance | |
# i.e. ghost1 ghost2 etc | |
# edit APP_DIR to each specific Ghost install directory | |
NAME=ghost1 | |
APP_DIR=/home/nginx/domains/ghost.centminmod.com/ghost | |
APP_START=index.js | |
APP_NAME=$NAME | |
PID=$(su -l $USER -c "$NODE $PM2 list" | grep "$APP_NAME" | awk '{print $4}') | |
PROXYCACHE=y | |
PROXYCACHEDIR='/home/nginx/domains/ghost.centminmod.com/ghostcache' | |
########################################### | |
ngxcache() { | |
if [[ "$PROXYCACHE" = [yY] ]]; then | |
# clear proxy_cache | |
# i.e. nginx.conf | |
# proxy_cache_path /home/nginx/domains/ghost.centminmod.com/ghostcache levels=1:2 keys_zone=ghostcache:80m | |
# max_size=100m inactive=60m; | |
rm -rf ${PROXYCACHEDIR}/* | |
service nginx restart | |
fi | |
} | |
super() { | |
su -l $USER -c "$1 $2 $3 $4 $5 $6 $7 $8" | |
} | |
start() { | |
echo "Starting $NAME" | |
cd $APP_DIR | |
super NODE_ENV=production $NODE $PM2 start ${APP_DIR}/${APP_START} -x --name $APP_NAME | |
} | |
stop() { | |
echo "Shutting down $NAME" | |
cd $APP_DIR | |
super $NODE $PM2 stop $PID | |
} | |
restart() { | |
echo "Restarting $NAME" | |
stop | |
start | |
ngxcache | |
} | |
status() { | |
echo "Status for $NAME:" | |
cd $APP_DIR | |
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