-
Notifications
You must be signed in to change notification settings - Fork 8
/
dockerctl.sh
executable file
·62 lines (55 loc) · 1.54 KB
/
dockerctl.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
#!/bin/bash
DAEMON="dockerd"
DIR_LOGS="/workspace/logs"
DOCKERD_LOG="${DIR_LOGS}/dockerd.log"
case "${1}" in
start)
# Call dockerd-entrypoint to start dockerd, then check that dockerd has started
#
if ! test -d ${DIR_LOGS}
then
echo "Creating logging directory: ${DIR_LOGS}"
mkdir -p ${DIR_LOGS}
fi
# Start the docker daemon in the background
echo "Starting dockerd with '--mtu=1440' in order to be compatible with Calico on K8S"
bash /usr/local/bin/dockerd-entrypoint.sh --mtu=1440 > ${DOCKERD_LOG} 2>&1 &
echo "dockerd logs redirected to:${DOCKERD_LOG}"
# Check if dockerd has started
while ! /usr/bin/pgrep ${DAEMON}
do
echo "Waiting for dockerd pid"
sleep 14
done
PID=`/usr/bin/pgrep $DAEMON`
echo "${DAEMON} pid:${PID}"
if [ "${PID}" ]
then
while ! docker stats --no-stream
do
echo "Waiting for dockerd to start"
sleep 10
if [[ ! -z ${DOCKER_SECRET_AUTH+z} ]] && [ ! -d /root/.docker ]
then
mkdir /root/.docker
echo "${DOCKER_SECRET_AUTH}" > /root/.docker/config.json
echo "Docker login"
fi
echo "Launching docker info"
docker info
done
fi
;;
stop)
/usr/bin/pkill ${DAEMON}
sleep 10
while /usr/bin/pgrep ${DAEMON} && ! ps -e | grep ${DAEMON} | grep -q defunct
do
/usr/bin/pkill -9 ${DAEMON}
sleep 5
done
;;
*)
echo "Usage: ${0} [start|stop]"
;;
esac