Skip to content

Instantly share code, notes, and snippets.

@rdeavila
Last active August 29, 2015 13:57
Show Gist options
  • Save rdeavila/9391092 to your computer and use it in GitHub Desktop.
Save rdeavila/9391092 to your computer and use it in GitHub Desktop.
Script init.d para inicializar node
#!/bin/sh
NODE_ENV="production"
NODE_APP='index.js'
APP_DIR='/opt/syonet/screenshot-service';
PID_FILE=$APP_DIR/app.pid
LOG_FILE=$APP_DIR/app.log
CONFIG_DIR=$APP_DIR
PORT=4001
NODE_EXEC=`which node`
###############
# REDHAT chkconfig header
# chkconfig: - 58 74
# description: node-screenshot, script para iniciar o screenshot-service na inicialização.
### BEGIN INIT INFO
# Provides: node
# Required-Start: $network $remote_fs $local_fs $postgresql
# Required-Stop: $network $remote_fs $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop node screenshot service
# Description: Node process for screenshot service
### END INIT INFO
start_app (){
if [ -f $PID_FILE ]
then
echo "O arquivo $PID_FILE existe. Ou o processo ainda está rodando, ou foi encerrado de forma forçada."
else
echo "Iniciando o screenshot service..."
PORT=$PORT NODE_ENV=$NODE_ENV NODE_CONFIG_DIR=$CONFIG_DIR $NODE_EXEC $APP_DIR/$NODE_APP 1>$LOG_FILE 2>&1 &
echo $! > $PID_FILE;
fi
}
stop_app (){
if [ ! -f $PID_FILE ]
then
echo "O arquivo $PID_FILE não existe. Processo não está rodando."
else
echo "Encerrando $APP_DIR/$NODE_APP ..."
echo "Encerrando processo com pid `cat $PID_FILE`"
kill `cat $PID_FILE`;
rm -f $PID_FILE;
echo "Screenshot service parou."
fi
}
case "$1" in
start)
start_app
;;
stop)
stop_app
;;
restart)
stop_app
start_app
;;
status)
if [ -f $PID_FILE ]
then
PID=`cat $PID_FILE`
if [ -z "`ps -ef | grep $PID | grep -v grep`" ]
then
echo "O Screenshot service parou, mas o pid file ainda existe"
else
echo "O Screenshot service está rodando com pid $PID"
fi
else
echo "O Screenshot service está parado."
fi
;;
*)
echo "Uso: /etc/init.d/node-screenshot {start|stop|restart|status}"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment