-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor_service.sh
97 lines (88 loc) · 1.6 KB
/
monitor_service.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
SYSTEM_NAME=Monitor_Stack
STACK_NAME=monitor_stack
STACK_NETWORK=monitor_network
ELASTIC_VERSION=8.2.0
NODE_LIST=$(echo $(docker node ls --format "{{ .Hostname }}") | sed "s/\s/,/g")
isRunning() {
[ ! -z $(docker stack ls --format "{{ .Name }}") ] && return
}
start() {
if ! isRunning
then
echo "Run $SYSTEM_NAME"
export ELASTIC_VERSION=$ELASTIC_VERSION
export NODE_LIST=$NODE_LIST
if [ -z "$(docker network ls | grep $STACK_NETWORK)" ]
then
docker network create --driver overlay --attachable $STACK_NETWORK
fi
docker stack deploy --compose-file docker-compose.yml $STACK_NAME
else
echo "$SYSTEM_NAME is running"
fi
}
stop() {
if isRunning
then
echo "Stop $SYSTEM_NAME"
docker stack rm $STACK_NAME
else
echo "$SYSTEM_NAME is not running"
fi
}
restart() {
if isRunning
then
stop
echo "Wating 3 sec..."
sleep 3s
start
else
echo "$SYSTEM_NAME is not running"
fi
}
status() {
if isRunning
then
docker service ls
else
echo "$SYSTEM_NAME is not running"
fi
}
logs() {
if isRunning
then
docker service logs "${STACK_NAME}"_$1
else
echo "$SYSTEM_NAME is not running"
fi
}
update() {
if isRunning
then
docker service update --force --update-failure-action "rollback" "${STACK_NAME}"_$1
else
echo "$SYSTEM_NAME is not running"
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
logs)
logs $2
;;
update)
update $2
;;
esac