-
-
Save stolsma/11211444 to your computer and use it in GitHub Desktop.
Revisions
-
sumpton revised this gist
Jun 14, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ #!/bin/bash # # chkconfig: - 55 45 # init.d example for Forever & Node # # modeled after -
sumpton revised this gist
Jun 14, 2013 . 1 changed file with 59 additions and 54 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -34,77 +34,82 @@ AWK=awk SED=sed start() { echo "Starting $NAME node instance: " if [ "$FOREVER_ID" = "" ]; then # Create the log and pid files, making sure that the target use has access to them mkdir -p $PID_DIR chown $USER $PID_DIR mkdir -p $LOG_DIR chown $USER $LOG_DIR touch $LOGFILE chown $USER $LOGFILE touch $PIDFILE chown $USER $PIDFILE # Launch the application daemon $FOREVER start -p $FOREVER_DIR --pidFile $PIDFILE -l $LOGFILE -a --sourceDir $INSTANCE_DIR -c $COMMAND $SOURCE_NAME RETVAL=$? else echo "Instance already running" RETVAL=0 fi } restart() { echo -n "Restarting $NAME node instance : " if [ "$FOREVER_ID" != "" ]; then $FOREVER restart -p $FOREVER_DIR $FOREVER_ID RETVAL=$? else start fi } stop() { echo -n "Shutting down $NAME node instance : " if [ "$FOREVER_ID" != "" ]; then $FOREVER stop -p $FOREVER_DIR $FOREVER_ID else echo "Instance is not running"; fi RETVAL=$? } getForeverId() { # local PID=$(pidofproc -p $PIDFILE) read PID < $PIDFILE #$FOREVER list -p $FOREVER_DIR | $SED -e 's/\x1b\[[0-9; ]*m//g' | $AWK "\$6 && \$6 == \"$pid\" { gsub(/[\[\]]/, \"\", \$2); print \$2; }"; $FOREVER list | grep $PID | $AWK "\$7 && \$7 == \"$PID\" { gsub(/[\[\]]/, \"\", \$2); print \$2; }" } if [ -f $PIDFILE ]; then FOREVER_ID=$(getForeverId) #echo ID: $FOREVER_ID else FOREVER_ID='' fi case "$1" in start) start ;; stop) stop ;; status) status -p ${PIDFILE} ;; restart) restart ;; *) echo "Usage: {start|stop|status|restart}" exit 1 ;; esac exit $RETVAL -
sumpton revised this gist
Jun 14, 2013 . 1 changed file with 49 additions and 36 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,48 +1,58 @@ #!/bin/bash # # init.d example for Forever & Node # # modeled after # https://gist.github.com/jinze/3748766 # # supports vhost # # pidfile: /var/run/nodejs/initd-example.pid # logfile: /var/log/nodejs/initd-example.log # Source function library. . /etc/init.d/functions NAME=feeds-process # Unique name for the application NODE_ENV=production # Node environment PORT=3000 # Port (in this case the application uses process.env.PORT to set the port) SOURCE_NAME=app.js # Name os the applcation entry point script USER=nodejs INSTANCE_DIR=/var/www/$NAME # Location of the application source COMMAND=node # Command to run PID_DIR=/var/run/nodejs PIDFILE=$PID_DIR/$NAME.pid LOG_DIR=/var/log/nodejs LOGFILE=$LOG_DIR/$NAME.log FOREVER_DIR=/var/run/forever # Forever root directory. NODE=node FOREVER=/usr/bin/forever AWK=awk SED=sed start() { echo "Starting $NAME node instance: " if [ "$ID" = "" ]; then # Create the log and pid files, making sure that the target use has access to them mkdir -p $PID_DIR chown $USER $PID_DIR mkdir -p $LOG_DIR chown $USER $LOG_DIR touch $LOGFILE chown $USER $LOGFILE touch $PIDFILE chown $USER $PIDFILE # Launch the application daemon $FOREVER start -p $FOREVER_DIR --pidFile $PIDFILE -l $LOGFILE -a --sourceDir $INSTANCE_DIR -c $COMMAND $SOURCE_NAME RETVAL=$? else echo "Instance already running" @@ -52,8 +62,8 @@ start() { restart() { echo -n "Restarting $NAME node instance : " if [ "$ID" != "" ]; then $FOREVER restart -p $FOREVER_DIR $ID RETVAL=$? else start @@ -62,19 +72,22 @@ restart() { stop() { echo -n "Shutting down $NAME node instance : " if [ "$ID" != "" ]; then $FOREVER stop -p $FOREVER_DIR $ID else echo "Instance is not running"; fi RETVAL=$? } getForeverId() { local PID=$(pidofproc -p $PIDFILE) #$FOREVER list -p $FOREVER_DIR | $SED -e 's/\x1b\[[0-9; ]*m//g' | $AWK "\$6 && \$6 == \"$pid\" { gsub(/[\[\]]/, \"\", \$2); print \$2; }"; $FOREVER list | grep $PID | $AWK "\$7 && \$7 == \"$PID\" { gsub(/[\[\]]/, \"\", \$2); print \$2; }" } ID=$(getForeverId) #echo ID: $ID case "$1" in start) @@ -84,7 +97,7 @@ case "$1" in stop ;; status) status -p ${PIDFILE} ;; restart) restart -
jinze created this gist
Sep 19, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,97 @@ #!/bin/bash # # initd-example Node init.d # # chkconfig: 345 80 20 # description: Node init.d example # processname: node # pidfile: /var/run/initd-example.pid # logfile: /var/log/initd-example.log # # Source function library. . /lib/lsb/init-functions NAME=initd-example # Unique name for the application NODE_ENV=production # Node environment PORT=1234 # Port (in this case the application uses process.env.PORT to set the port) INSTANCE_DIR=/var/www/$NAME # Location of the application source COMMAND=coffee # Command to run SOURCE_NAME=app.coffee # Name os the applcation entry point script user=apache pidfile=/var/run/$NAME.pid logfile=/var/log/$NAME.log forever_dir=/var/run/forever # Forever root directory. node=node forever=forever awk=awk sed=sed start() { echo "Starting $NAME node instance: " if [ "$id" = "" ]; then # Create the log and pid files, making sure that the target use has access to them touch $logfile chown $user $logfile touch $pidfile chown $user $pidfile # Launch the application start_daemon $forever start -p $forever_dir --pidFile $pidfile -l $logfile -a -d $INSTANCE_DIR -c $COMMAND $SOURCE_NAME RETVAL=$? else echo "Instance already running" RETVAL=0 fi } restart() { echo -n "Restarting $NAME node instance : " if [ "$id" != "" ]; then $forever restart -p $forever_dir $id RETVAL=$? else start fi } stop() { echo -n "Shutting down $NAME node instance : " if [ "$id" != "" ]; then $forever stop -p $forever_dir $id else echo "Instance is not running"; fi RETVAL=$? } getForeverId() { local pid=$(pidofproc -p $pidfile) $forever list -p $forever_dir | $sed -e 's/\x1b\[[0-9; ]*m//g' | $awk "\$6 && \$6 == \"$pid\" { gsub(/[\[\]]/, \"\", \$2); print \$2; }"; } id=$(getForeverId) case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} ;; restart) restart ;; *) echo "Usage: {start|stop|status|restart}" exit 1 ;; esac exit $RETVAL