-
-
Save ivankravchenko/7708703 to your computer and use it in GitHub Desktop.
handy hipache provision script
installation:
curl https://gist.github.com/krava/7708703/raw/3c4828c832ec63c66575339f0d1cd7647b0cc62c/edge > /sbin/edge && chmod u+x /sbin/edge
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 | |
COMMAND=$1 | |
HOST=$2 | |
case $COMMAND in | |
add) | |
shift;shift | |
if [[ ! $HOST ]]; then | |
echo No host specified. | |
exit 409 | |
elif [[ `redis-cli exists frontend:$HOST` =~ "0" ]]; then | |
redis-cli rpush frontend:$HOST $HOST >/dev/null && echo AH $HOST | |
elif [ $# -eq 0 ]; then | |
echo Host $HOST exists. | |
exit 409 | |
fi | |
if [ $# -gt 0 ]; then | |
for B in "$@"; do | |
redis-cli rpush frontend:$HOST $B > /dev/null && echo AB $HOST $B | |
done | |
fi | |
;; | |
remove) | |
shift;shift | |
if [[ ! $HOST ]]; then | |
echo No host specified. | |
exit 409 | |
elif [[ `redis-cli exists frontend:$HOST` =~ "0" ]]; then | |
echo Host $HOST not found. | |
exit 404 | |
elif [ $# -eq 0 ]; then | |
redis-cli del frontend:$HOST >/dev/null && echo RH $HOST | |
else | |
for B in "$@"; do | |
redis-cli lrem frontend:$HOST 0 $B >/dev/null && echo RB $HOST $B | |
done | |
fi | |
;; | |
list) | |
if [[ ! $HOST ]]; then | |
redis-cli --raw keys frontend:* | sed 's/^frontend://' | |
elif [[ `redis-cli exists frontend:$HOST` =~ "1" ]]; then | |
redis-cli --raw lrange frontend:$HOST 1 -1 | |
else | |
echo Host $HOST not found. | |
exit 404 | |
fi | |
;; | |
*) | |
echo Usage: edge [add,remove,list] [host] [backend] [backend...] | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment