Topic: Debian: Restarting Backgroundrb And Zebra on Reboot
Topic type:
Steps required to restart Backgroundrb And Zebra on Reboot, for a Debian operating system.
Init.d Script to Start / Stop BackgroundRB and Zebra
Save the following to /etc/init.d/kete_backgroundrb_and_zebra_boot (do not change this path name)
Edit the three variables at the top of the file to suit your environment:
- RUBY_BIN
- Where you can find the ruby and rake executables
- DEPLOYED_KETE
- The name of the folder containing a deployed application, i.e. /home/kete/apps/[your_app]/current (space separated)
- NON_DEPLOYED_KETE
- The name of the folder containing a non-deployed application, i.e. /home/kete/apps/[your_app] (space separated)
- LOG_FILE
- Where the result of the reboot startup script should be placed. Will be owned by the user that starts up the script (kete).
#!/bin/bash
# Reboot all Backgroundrb and Kete instances
RUBY_BIN=/opt/ree-latest/bin
DEPLOYED_KETE="your_app"
NON_DEPLOYED_KETE="your_other_app"
LOG_FILE="/home/kete/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}/current"; 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"
/bin/su -l kete -c "/usr/bin/env ruby '$1/script/backgroundrb' start >> $LOG_FILE" kete - kete
/bin/su -l kete -c "/usr/bin/env 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
Getting Debian to use this init.d script
Then run the following as root to symlink the script where it needs to be.
root@host: # cd /etc/init.d
root@host: # chmod 755 kete_backgroundrb_and_zebra_boot
root@host: # chown kete:kete kete_backgroundrb_and_zebra_boot
root@host: # update-rc.d kete_backgroundrb_and_zebra_boot start 99 2 3 4 5 .
We only tell Debian to use it during start up. The 99 means it's one of the last things to come online (after memcache, apache etc) when the system starts up. The "2 3 4 5 ." means that any type of start up (non gui/gui-x11, single/multi user) should trigger this.
Backgroundrb and Zebra can now start up automatically after a start up / restart.
Additional Features
It also provides the ability to run commands outside of start up. For example, run these when logged in as the kete user:
$ /etc/init.d/kete_backgroundrb_and_zebra_boot stop # Free Memory
$ /etc/init.d/kete_backgroundrb_and_zebra_boot start # Start them after stop
$ /etc/init.d/kete_backgroundrb_and_zebra_boot restart # Does both stop, then start

