Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active September 30, 2015 15:33
Show Gist options
  • Save coderofsalvation/e0a516c5dfe11cd1c64d to your computer and use it in GitHub Desktop.
Save coderofsalvation/e0a516c5dfe11cd1c64d to your computer and use it in GitHub Desktop.
hipcli - a simple bash interface to hipache
$ hipcli
Usage:
hipcli add <id> <domain> <url_dest:port>
hipcli del <id> <domain>
hipcli list
$ hipcli add flop flop.com http://127.0.0.1:2903
$ hipcli list
domain id destination
---------------------------------------- -------------------- ----------------------
frontend:flop.com flop http://127.0.0.1:2903
$ hipcli del flop flop.com
#!/bin/bash
# deadsimple bash interface to hipache
#
# Copyright (c) 2015, Leon van Kammen (https://github.com/coderofsalvation)
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation,
# advertising materials, and other materials related to such
# distribution and use acknowledge that the software was developed
# by the <organization>. The name of the
# <organization> may not be used to endorse or promote products derived
# from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# installation:
# $ wget https://gist.githubusercontent.com/coderofsalvation/e0a516c5dfe11cd1c64d/raw/072b2cca27764f4ede0c04fcced8ae67f0d4c5e2/hipcli
# $ chmod 755 hipcli && sudo mv hipcli /usr/bin/.
# $ hipcli
# done!
cmdname=hipcli
[[ ! -n $1 ]] && {
echo "Usage:
$cmdname add <id> <domain> <url_dest:port>
$cmdname del <id> <domain>
$cmdname list
"; exit 1;
}
add(){
[[ ! -n $1 ]] && { echo "Usage: add <id> <domain> <url_dest:port>"; exit 1; }
ID=${1};
SOURCE="$2"; shift; shift; DEST="$*"
redis-cli <<EOF
del frontend:${SOURCE} ${ID}
rpush frontend:${SOURCE} ${ID}
rpush frontend:${SOURCE} ${DEST}
lrange frontend:${SOURCE} 0 -1
EOF
}
del(){
[[ ! -n $1 ]] && { echo "Usage: del <id> <domain>"; exit 1; }
ID=${1}; SOURCE="$2"
redis-cli <<EOF
del frontend:${SOURCE} ${ID}
lrange frontend:${SOURCE} 0 -1
EOF
}
list(){
keys=$(
redis-cli <<EOF
keys *
EOF
)
printf "%-60s %-20s %s\n" domain id destination
printf -- "------------------------------------------------------------ -------------------- ----------------------\n"
echo "$keys" | while read line; do echo "$line"; redis-cli lrange $line 0 -1; done | awk '{getline b; getline c;printf("%-60s %-20s %s\n",$0,b,c)}'
}
"$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment