Created
September 15, 2014 13:49
-
-
Save maximilize/6121357506963af6417f to your computer and use it in GitHub Desktop.
Circus start/stop/restart for more than one watcher at once
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 characters
| #!/bin/bash | |
| run_circusctl() { | |
| for i in {1..50} | |
| do | |
| OUT=$(circusctl $@ 2>&1) | |
| if [ "$OUT" = "ok" ] | |
| then | |
| echo >&2 | |
| return | |
| elif [ $(echo "$OUT" | grep 'error: arbiter is already running ' | wc -l) = 1 ] | |
| then | |
| echo -n " ." >&2 | |
| sleep 0.1 | |
| else | |
| echo " $OUT" >&2 | |
| exit 1 | |
| fi | |
| done | |
| echo " timed out" >&2 | |
| exit 1 | |
| } | |
| reverse() { | |
| REV="" | |
| for x in $1 | |
| do | |
| REV="$x $REV" | |
| done | |
| echo "$REV" | |
| } | |
| usage() { | |
| echo "Usage: $0 <start|stop|restart> <watcher name>" >&2 | |
| exit 1 | |
| } | |
| start() { | |
| for watcher in $(reverse "$WATCHER") | |
| do | |
| echo -n "Starting $NAME-$watcher" >&2 | |
| run_circusctl start "$NAME-$watcher" | |
| done | |
| } | |
| stop() { | |
| for watcher in $WATCHER | |
| do | |
| echo -n "Stopping $NAME-$watcher" >&2 | |
| run_circusctl stop "$NAME-$watcher" | |
| REV="$watcher $REV" | |
| done | |
| } | |
| restart() { | |
| stop | |
| start | |
| } | |
| [ "$2" = "" ] && usage | |
| NAME="$2" | |
| CONF=/etc/circus/conf.d | |
| WATCHER=$( | |
| for watcher in $(ls "$CONF" | egrep "^watcher-$NAME-") | |
| do | |
| PRIORITY=$(grep ^priority "$CONF/$watcher" | sed -e 's/^priority.*=[^0-9]*//') | |
| echo "$PRIORITY $watcher" | |
| done | sort -n | awk '{print $2}' | sed -e "s/^watcher-$NAME-\(.*\)\.ini\$/\\1/" | |
| ) | |
| case $1 in | |
| start) | |
| start | |
| ;; | |
| stop) | |
| stop | |
| ;; | |
| restart) | |
| stop | |
| start | |
| ;; | |
| *) | |
| usage | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment