-
Notifications
You must be signed in to change notification settings - Fork 130
/
run.sh
executable file
·51 lines (44 loc) · 1.66 KB
/
run.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
#!/bin/bash
# grab global variables
source vars
DOCKER=$(which docker)
# function to check if container is running
function check_container() {
$DOCKER ps --filter "name=${CONTAINER_NAME}" --format "{{.ID}}"
}
# function to start new docker container
function start_container() {
$DOCKER run --name=${CONTAINER_NAME} \
--detach=true \
--restart=always \
--publish=123:123/udp \
--env=NTP_SERVERS=${NTP_SERVERS} \
--env=ENABLE_NTS=${ENABLE_NTS} \
--env=NOCLIENTLOG=${NOCLIENTLOG} \
--env=LOG_LEVEL=${LOG_LEVEL} \
--read-only=true \
--tmpfs=/etc/chrony:rw,mode=1750 \
--tmpfs=/run/chrony:rw,mode=1750 \
--tmpfs=/var/lib/chrony:rw,mode=1750 \
${DOCKER_OPTS} \
${IMAGE_NAME}:latest > /dev/null
}
# check if docker container with same name is already running.
if [ "$(check_container)" != "" ]; then
# container found...
# 1) rename existing container
$DOCKER rename ${CONTAINER_NAME} "${CONTAINER_NAME}_orig" > /dev/null 2>&1
# 2) stop exiting container
$DOCKER stop "${CONTAINER_NAME}_orig" > /dev/null 2>&1
# 3) start new container
start_container
# 4) remover existing container
if [ "$(check_container)" != "" ]; then
$DOCKER rm "${CONTAINER_NAME}_orig" > /dev/null 2>&1
fi
# finally, lets clean up old docker images
$DOCKER rmi $($DOCKER images -q ${IMAGE_NAME}) > /dev/null 2>&1
# no docker container found. start a new one.
else
start_container
fi