forked from spro/simon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimon-says
executable file
·34 lines (26 loc) · 1010 Bytes
/
simon-says
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Helper script to manage Simon routes a bit more simply
# Usage: simon-says [hostname] [destination]
# Destination should be in the form [ip]:[port] or just :[port] to imply localhost
# To remove a destination, add a "-" in front, e.g. -:5555
# To list existing destinations, leave out the last argument
HOSTNAME=$1
DESTINATION=$2
if [[ ! -z $DESTINATION ]]; then
# If the destination starts with "-", remove it
if [[ $DESTINATION = \-* ]]; then
DESTINATION=${DESTINATION:1}
REMOVE=true
fi
# If the destination starts with ":", prefix with the local IP
if [[ $DESTINATION = \:* ]]; then
DESTINATION=127.0.0.1$DESTINATION
fi
if [ "$REMOVE" = true ]; then
redis-cli srem simon:$HOSTNAME $DESTINATION | echo "Not pointing $HOSTNAME to $DESTINATION"
else
redis-cli sadd simon:$HOSTNAME $DESTINATION | echo "Pointing $HOSTNAME to $DESTINATION"
fi
fi
# List all assigned destinations
redis-cli smembers simon:$HOSTNAME