Skip to content

Instantly share code, notes, and snippets.

@fredv
Created July 27, 2010 16:39
Show Gist options
  • Save fredv/492482 to your computer and use it in GitHub Desktop.
Save fredv/492482 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Spawns a rescue worker configured according to local hostname.
# See the 'case'-block at the end of this file.
#
# make sure we have our environment
source ~/.bash_profile
# simfy hack; legible hostnames
# all hosts appear as s*.o2
HN=${HOSTNAME}
if [ -e /etc/real_hostname ]; then
HN=`cat /etc/real_hostname`
HN=${HN}.o2
fi
function launch_worker {
# spins up a worker
# Argument 1: RAILS_ENV
# Argument 2: QUEUE_NAME
# Argument 3: COUNT (Number of worker processes)
export RAILS_ENV=$1
export QUEUE=$2
export COUNT=$3
cd /opt/simfy/app/simfy_production/current
export VERBOSE=1
( echo $! >${VAR}/state/resque_worker.pid; \
exec nohup rake environment resque:work 2>&1 ) \
| nohup logger -t "resque_worker" >/dev/null 2>&1 &
mypid=`cat ${VAR}/state/resque_worker.pid`
echo "worker spawned: q'${QUEUE}', env ${RAILS_ENV}, count $COUNT, pid ${mypid}"
}
case $HN in
s4.o2)
# NFS Server
# Argument 1: RAILS_ENV
# Argument 2: QUEUE_NAME
# Argument 3: COUNT (Number of worker processes)
launch_worker production nfs_server 4
launch_worker production facebook_queue 2
;;
s3.o2)
# DB Server
launch_worker production db_server 1
;;
s5.o2)
# Staging Server
launch_worker staging db_server 1
launch_worker staging nfs_server 1
launch_worker staging facebook_queue 1
;;
*)
echo "No worker configured for this host."
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment