forked from alvinhenrick/docker-serf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserf-functions
76 lines (62 loc) · 1.7 KB
/
serf-functions
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
: ${MYDOMAIN:=mycorp.kom}
: ${IMAGE:=alvinhenrick/serf}
: ${DOCKER_OPTS:="--dns 127.0.0.1 -p 7373 -p 7946"}
: ${DEBUG:=1}
serf-settings() {
cat <<EOF
FIRST_IP=$FIRST_IP
MYDOMAIN=$MYDOMAIN
IMAGE=$IMAGE
DOCKER_OPTS=$DOCKER_OPTS
EOF
}
debug() {
[ -z $DEBUG ] || echo [DEBUG] $@
}
docker-ps() {
docker ps|sed "s/ \{3,\}/#/g"|cut -d '#' -f 1,2,7|sed "s/#/\t/g"
}
alias dps=docker-ps
serf-set-first-ip() {
: ${FIRST_IP:=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" node0)}
echo FIRST_IP=$FIRST_IP
}
serf-start-first() {
CMD="docker run -d $DOCKER_OPTS --name node0 -h node0.$MYDOMAIN $IMAGE"
debug $CMD
FIRST=$($CMD)
serf-set-first-ip
}
serf-start-slave() {
serf-set-first-ip
: ${FIRST_IP:?"FIRST_IP is needed"}
NUMBER=${1:?"please give a <NUMBER> parameter it will be used as node<NUMBER>"}
if [ $# -eq 1 ] ;then
MORE_OPTIONS="-d"
else
shift
MORE_OPTIONS="$@"
fi
CMD="docker run $MORE_OPTIONS -e JOIN_IP=$FIRST_IP $DOCKER_OPTS --name node$NUMBER -h node${NUMBER}.$MYDOMAIN $IMAGE"
debug $CMD
$CMD
}
serf-start-slave-foreground() {
NUMBER=${1:?"please give a <NUMBER> parameter it will be used as node<NUMBER>"}
serf-start-slave $1 -t -i
}
serf-start-cluster() {
NUM_OF_NODES=${1:-3}
echo starting $NUM_OF_NODES docker container
serf-start-first
for i in $(seq $((NUM_OF_NODES - 1))); do
serf-start-slave $i
done
}
# starts a serf container, joins to cluster, and starts a bash
serf-test-instance() {
serf-set-first-ip
docker run -i -t --rm $DOCKER_OPTS --name node99 -h node99.$MYDOMAIN -e JOIN_IP=$FIRST_IP $IMAGE bash -c '(nohup /etc/serf/start-serf-agent.sh &) && /bin/bash'
}
alias serf-reload-functions=". serf-functions"