forked from ake-persson/etcdtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-etcd.sh
executable file
·77 lines (68 loc) · 1.78 KB
/
init-etcd.sh
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
77
#!/bin/bash
IMAGE='quay.io/coreos/etcd:latest'
NAME='etcd'
case $(uname -s) in
'Darwin')
HOST_PORT=${DOCKER_HOST#tcp://}
IP=${HOST_PORT%:[0-9]*}
;;
'Linux')
IP=$(ifconfig eth0 | awk '/inet / {print $2}')
;;
esac
start() {
docker run -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p 4001:4001 -p 2380:2380 -p 2379:2379 \
--name ${NAME}0 quay.io/coreos/etcd:v2.0.8 \
-name ${NAME}0 \
-advertise-client-urls http://${IP}:2379,http://${IP}:4001 \
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
-initial-advertise-peer-urls http://${IP}:2380 \
-listen-peer-urls http://0.0.0.0:2380 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster etcd0=http://${IP}:2380 \
-initial-cluster-state new
}
stop() {
docker stop ${NAME}0
docker rm ${NAME}0
}
status() {
echo NODE1: ${NAME}1 IP: ${IP} PORT: 4001
}
error() {
echo "$1" >&2
exit 1
}
which docker &>/dev/null || error "Docker binary is not in the \$PATH"
docker ps &>/dev/null || error "Can't talk to the Docker daemon, either start the daemon or setup the required env. variables"
CMD=$1
case ${CMD} in
'start')
start
sleep 1
status
echo "# Run the following to export the environment"
echo "# eval \"\$(./init-etcd.sh env)\""
;;
'stop')
stop
;;
'restart')
stop
start
sleep 1
status
;;
'status')
status
;;
'env')
echo "export ETCDCTL_PEERS=\"http://${IP}:4001\""
echo "export ETCDTOOL_PEERS=\"http://${IP}:4001\""
echo "# Run the following to export the environment"
echo "# eval \"\$(./init-etcd.sh env)\""
;;
*)
echo "Usage: $0 {start|stop|restart|status|env}"
;;
esac