Created
July 4, 2013 08:05
-
-
Save MagnusEnger/5925789 to your computer and use it in GitHub Desktop.
kete_backgroundrb_and_zebra_boot
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 | |
### BEGIN INIT INFO | |
# Provides: kbzb | |
# Required-Start: $mysql $all | |
# Required-Stop: $mysql | |
# Default-Start: 2 | |
# Default-Stop: | |
# Short-Description: Reboot all Backgroundrb and Zebra for Kete instances | |
### END INIT INFO | |
RUBY_BIN=/opt/ruby-enterprise-1.8.7-2012.02/bin | |
DEPLOYED_KETE=myapp | |
# NON_DEPLOYED_KETE="your_other_app" | |
LOG_FILE="/home/kete/myapp_reboot.log" | |
# DO NOT EDIT PAST THIS POITN | |
set -e | |
PATH=$RUBY_BIN:/bin:/usr/bin:/sbin:/usr/sbin:$PATH | |
function start_backgroundrb_and_zebra { | |
log ""; log "Starting zebra and background - `date +%Y-%m-%d`" | |
/bin/su -c "chown kete:kete $LOG_FILE" | |
for app in `echo $DEPLOYED_KETE`; do start_up "/home/kete/apps/${app}"; done | |
for app in `echo $NON_DEPLOYED_KETE`; do start_up "/home/kete/apps/${app}"; done | |
/bin/su -c "chown kete:kete $LOG_FILE" | |
} | |
function stop_backgroundrb_and_zebra { | |
killall zebrasrv | |
killall ruby | |
} | |
function start_up { | |
log ""; log "Starting up Zebra and BackgroundRB for $1" | |
# su command strips PATH from env, thus we have to specify full path to ruby commands | |
/bin/su -l kete -c "/usr/bin/env $RUBY_BIN/ruby '$1/script/backgroundrb' start >> $LOG_FILE" kete - kete | |
/bin/su -l kete -c "/usr/bin/env $RUBY_BIN/rake -f '$1/Rakefile' '$1/' zebra:start >> $LOG_FILE" kete - kete | |
} | |
function log { | |
echo $1 >> $LOG_FILE | |
} | |
case "$1" in | |
start) | |
start_backgroundrb_and_zebra | |
;; | |
stop) | |
stop_backgroundrb_and_zebra | |
;; | |
restart | reboot | reload) | |
stop_backgroundrb_and_zebra | |
start_backgroundrb_and_zebra | |
;; | |
*) | |
echo "Usage: /etc/init.d/kete_backgroundrb_and_zebra_boot {start|stop|restart|reboot}" >&2 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment