-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands
executable file
·107 lines (92 loc) · 2.72 KB
/
commands
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
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
DOKKU_NODEEXPORTER_IMAGE="prom/node-exporter:v0.15.2"
DOKKU_NODEEXPORTER_CONTAINER=nodeexporter
DOKKU_NODEEXPORTER_DEFAULT_PORT=9100
DOKKU_NODEEXPORTER_PORT="${DOKKU_NODEEXPORTER_PORT:-$DOKKU_NODEEXPORTER_DEFAULT_PORT}"
DOKKU_NODEEXPORTER_ARGS="--path.procfs=/host/proc --path.sysfs=/host/sys --collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($|/)"
f_check_container() {
local l_status
l_status="$(docker inspect -f '{{.State.Running}}' $DOKKU_NODEEXPORTER_CONTAINER 2>/dev/null)" || l_status=none
printf "%s" "$l_status"
}
# Start the container
f_dokku_nodeexporter_start() {
case $(f_check_container) in
none)
echo "Starting nodeexporter on port ${DOKKU_NODEEXPORTER_PORT} ..."
docker run \
--user root \
--privileged \
--volume=/proc:/host/proc:ro \
--volume=/sys:/host/sys:ro \
--volume=/:/rootfs:ro \
--publish="$DOKKU_NODEEXPORTER_PORT:9100" \
--detach=true \
--name="$DOKKU_NODEEXPORTER_CONTAINER" \
$DOKKU_NODEEXPORTER_IMAGE \
$DOKKU_NODEEXPORTER_ARGS \
> /dev/null
;;
false)
echo "Starting nodeexporter on port ${DOKKU_NODEEXPORTER_PORT} ..."
docker start "$DOKKU_NODEEXPORTER_CONTAINER" >/dev/null
;;
*)
echo "nodeexporter is already running"
;;
esac
}
# Stop the container
f_dokku_nodeexporter_stop() {
case $(f_check_container) in
true)
echo "Stopping nodeexporter ..."
docker stop "$DOKKU_NODEEXPORTER_CONTAINER" >/dev/null
;;
*)
echo "nodeexporter is not running"
;;
esac
}
# Pull nodeexporter image
f_dokku_nodeexporter_install() {
docker pull "$DOKKU_NODEEXPORTER_IMAGE" >/dev/null
case $(f_check_container) in
true)
f_dokku_nodeexporter_start
docker rm "$DOKKU_NODEEXPORTER_CONTAINER" >/dev/null
f_dokku_nodeexporter_stop
;;
false)
docker rm "$DOKKU_NODEEXPORTER_CONTAINER" >/dev/null
;;
*) ;;
esac
}
case "$1" in
nodeexporter)
case $(f_check_container) in
true)
echo "nodeexporter is running on http://$(hostname -f):${DOKKU_NODEEXPORTER_PORT}/" ;;
*)
echo "nodeexporter is not running" ;;
esac ;;
nodeexporter:start)
f_dokku_nodeexporter_start ;;
nodeexporter:stop)
f_dokku_nodeexporter_stop ;;
nodeexporter:install)
f_dokku_nodeexporter_install ;;
help | nodeexporter:help)
cat<<EOF
nodeexporter, Show the status of nodeexporter
nodeexporter:start, Start nodeexporter service
nodeexporter:stop, Stop nodeexporter
EOF
;;
*)
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
;;
esac