Last active
January 8, 2016 16:36
-
-
Save mikz/3b0bc2ac97bfdf6263b4 to your computer and use it in GitHub Desktop.
Revisions
-
mikz revised this gist
Jan 8, 2016 . 2 changed files with 85 additions and 11 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,23 +1,35 @@ manual instance ${N} kill timeout 10800 # 3 hours in seconds setuid user stop on stopping resque env N env QUEUE="*" env TASK="environment resque:work" env RAKE="/usr/local/bin/rake" env BUNDLER="/usr/local/bin/bundle" env COUNT=1 env RAILS_ENV="staging" env DEFAULTFILE=/etc/default/resque chdir /home/user/system_staging/current script if [ -f "$DEFAULTFILE" ]; then . "$DEFAULTFILE" fi exec ${BUNDLER} exec ${RAKE} ${TASK} end script post-start script # wait for resque to boot and change its command name to resque-version while [ -z "${pid}" ] || ! ps -p ${pid} -o args | grep '^resque-' do pid=$(status ${UPSTART_JOB} N=${UPSTART_INSTANCE} | grep 'start/' | awk '{print $NF}') sleep 1 done end script 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,17 +1,79 @@ #!upstart #manual start on startup # stop on stopping resque-worker env QUEUE_1="*" env QUEUE_2="*" env QUEUE_3="*" env QUEUE_4="*" env QUEUE_5="*" env QUEUE_6="default" env WORKERS=6 kill timeout 60 # resque workers have higher timeout script start_worker () { start resque-worker N=${1} QUEUE=$(eval echo \$QUEUE_${1}) || : } start_workers () { for n in $(seq ${WORKERS}) do start_worker ${n} & done wait } restart_worker () { restart resque-worker N=${1} } stop_worker () { stop resque-worker N=${1} || : } reload_workers () { for n in $(seq ${WORKERS}) do restart_worker ${n} & done wait } stop_workers () { for n in $(seq ${WORKERS}) do stop_worker ${n} & done wait exit } trap reload_workers HUP trap stop_workers TERM start_workers while : do sleep 1 # just 1, so it can trap signals done end script post-start script while [ $(initctl list | grep resque-worker | grep start/running | wc -l) -ne ${WORKERS} ] do sleep 1 # wait until all the workers start done end script post-stop script for n in `initctl list|grep "^resque-worker "|awk '{print $2}'|tr -d ')'|tr -d '('` do stop resque-worker N=$n & done wait end script -
mikz revised this gist
Jan 5, 2016 . 2 changed files with 2 additions 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,3 +1,4 @@ #!upstart manual instance N=${N} 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,3 +1,4 @@ #!upstart start on startup stop on stopping resque-worker -
mikz renamed this gist
Jan 5, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mikz created this gist
Jan 5, 2016 .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,22 @@ manual instance N=${N} env N env QUEUE="*" env TASK="environment resque:work" env RAKE="/usr/local/bin/rake" env BUNDLER="/usr/local/bin/bundle" env COUNT=1 env RAILS_ENV="production" env DEFAULTFILE=/etc/default/resque chdir /home/bender/system_production/current script if [ -f "$DEFAULTFILE" ]; then . "$DEFAULTFILE" fi exec ${BUNDLER} exec ${RAKE} ${TASK} end script 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,16 @@ start on startup stop on stopping resque-worker pre-start script # TODO: loop start resque-worker N=0 QUEUE="foo,*" || true start resque-worker N=1 QUEUE="bar,*" || true end script pre-stop script for n in `initctl list|grep "^resque-worker "|awk '{print $2}'|tr -d ')'|tr -d '('` do stop resque-worker N=$n done end script