-
Notifications
You must be signed in to change notification settings - Fork 146
/
start-grafana-renderer.sh
executable file
·103 lines (97 loc) · 2.09 KB
/
start-grafana-renderer.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
98
99
100
101
102
103
#!/usr/bin/env bash
. versions.sh
if [ -f env.sh ]; then
. env.sh
fi
VERSION="$GRAFANA_RENDERER_VERSION"
DOCKER_PARAM=""
GRAFANA_NAME="agrafrender"
BIND_ADDRESS=""
GRAFANA_RENDPORT="8081"
usage="$(basename "$0") [-h] [-D encapsulate docker param] -- Start the grafana render container"
LIMITS=""
VOLUMES=""
PARAMS=""
for arg; do
shift
if [ -z "$LIMIT" ]; then
case $arg in
--limit)
LIMIT="1"
;;
--volume)
LIMIT="1"
VOLUME="1"
;;
--param)
LIMIT="1"
PARAM="1"
;;
*)
set -- "$@" "$arg"
;;
esac
else
DOCR=$(echo $arg | cut -d',' -f1)
VALUE=$(echo $arg | cut -d',' -f2- | sed 's/#/ /g')
NOSPACE=$(echo $arg | sed 's/ /#/g')
if [ "$PARAM" = "1" ]; then
if [ -z "${DOCKER_PARAMS[$DOCR]}" ]; then
DOCKER_PARAMS[$DOCR]=""
fi
DOCKER_PARAMS[$DOCR]="${DOCKER_PARAMS[$DOCR]} $VALUE"
PARAMS="$PARAMS --param $NOSPACE"
unset PARAM
else
if [ -z "${DOCKER_LIMITS[$DOCR]}" ]; then
DOCKER_LIMITS[$DOCR]=""
fi
if [ "$VOLUME" = "1" ]; then
SRC=$(echo $VALUE | cut -d':' -f1)
DST=$(echo $VALUE | cut -d':' -f2-)
SRC=$(readlink -m $SRC)
DOCKER_LIMITS[$DOCR]="${DOCKER_LIMITS[$DOCR]} -v $SRC:$DST"
VOLUMES="$VOLUMES --volume $NOSPACE"
unset VOLUME
else
DOCKER_LIMITS[$DOCR]="${DOCKER_LIMITS[$DOCR]} $VALUE"
LIMITS="$LIMITS --limit $NOSPACE"
fi
fi
unset LIMIT
fi
done
while getopts ':hlg:D:' option; do
case "$option" in
h)
echo "$usage"
exit
;;
l)
DOCKER_PARAM="$DOCKER_PARAM --net=host"
;;
D)
DOCKER_PARAM="$DOCKER_PARAM $OPTARG"
;;
:)
printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?)
printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
if [ "$(id -u)" -ne 0 ]; then
GROUPID=$(id -g)
USER_PERMISSIONS="-u $UID:$GROUPID"
fi
if [[ ! $DOCKER_PARAM = *"--net=host"* ]]; then
PORT_MAPPING="-p $GRAFANA_RENDPORT:8081"
fi
docker run ${DOCKER_LIMITS["grafanarender"]} -d $DOCKER_PARAM -i $USER_PERMISSIONS $PORT_MAPPING \
--name $GRAFANA_NAME docker.io/grafana/grafana-image-renderer:$VERSION \
${DOCKER_PARAMS["grafanarender"]}