-
Notifications
You must be signed in to change notification settings - Fork 0
/
keepalivedctl
71 lines (64 loc) · 1.65 KB
/
keepalivedctl
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
#!/bin/bash
set -xe
exec 2>&1
container_name="keepalived"
script_dir=$(
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd
)
keepalived_conf_dir="${script_dir}/keepalived"
keepalived_conf_template_file="${keepalived_conf_dir}/keepalived.${KEEPALIVED_ROLE}.template"
keepalived_conf_file="${keepalived_conf_dir}/keepalived.conf"
healthz_file="${keepalived_conf_dir}/harbor_healthz"
# prepare keepalived
if [ ! -d "/sys/module/ip_vs" ]; then
echo "loading ip_vs module"
modprobe ip_vs
fi
func_status() {
if [ "$(docker ps -qf name=$container_name)" ]; then
echo "keepalived is running..."
return 0
else
echo "keepalived is not running!"
return 1
fi
}
func_start() {
echo "generating $keepalived_conf_file"
if [ ! -e "$keepalived_conf_file" ]; then
touch "$keepalived_conf_file"
fi
envsubst <"$keepalived_conf_template_file" >"$keepalived_conf_file"
chmod 644 "$keepalived_conf_file"
chmod 744 "$healthz_file"
echo "running keepalived container"
docker run -d --rm \
--name=$container_name \
--cap-add=NET_ADMIN \
--cap-add=NET_BROADCAST \
--cap-add=NET_RAW \
--net=host \
--volume "$keepalived_conf_file":/usr/local/etc/keepalived/keepalived.conf \
--volume "$healthz_file":/etc/keepalived/harbor_healthz \
osixia/keepalived:2.0.17
}
func_stop() {
if func_status; then
docker stop $container_name
fi
}
case "$1" in
status)
func_status
;;
start)
func_start
;;
stop)
func_stop
;;
*)
echo "Usage: keepalivedctl status | start | stop"
;;
esac