From fff43fa3973f97578b4a217ecbb1b737bbe50aab Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Thu, 26 Jul 2018 14:56:40 +0200 Subject: [PATCH] fix: [docker-host] restart docker only if necessary --- precise/host/hooks/install.d/60-docker.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/precise/host/hooks/install.d/60-docker.sh b/precise/host/hooks/install.d/60-docker.sh index 9911b09..e47419d 100755 --- a/precise/host/hooks/install.d/60-docker.sh +++ b/precise/host/hooks/install.d/60-docker.sh @@ -1,17 +1,26 @@ #!/bin/bash - +need_restart= if ! type -p docker; then echo "Installing docker..." curl -sSL https://get.docker.io | sh fi -version="$(apt-cache madison docker-ce | cut -f 2 -d \| | grep 17.06 | head -n 1 | xargs echo)" -## DOWNGRADE to 17.xx because 18.xx do not support registry v1 -apt-get install -y --force-yes docker-ce="$version" +docker_version=17.06 +if ! [[ "$(docker --version)" == "Docker version $docker_version"* ]]; then + version="$(apt-cache madison docker-ce | cut -f 2 -d \| | grep "$docker_version" | head -n 1 | xargs echo)" + ## DOWNGRADE to 17.xx because 18.xx do not support registry v1 + apt-get install -y --force-yes docker-ce="$version" + need_restart=true +fi + if ! egrep 'disable-legacy-registry' /lib/systemd/system/docker.service 2>/dev/null; then sed -ri 's/^(ExecStart=.*)$/\1 --disable-legacy-registry=false/g' /lib/systemd/system/docker.service + need_restart=true fi -systemctl daemon-reload && -service docker restart + +if [ "$need_restart" ]; then + systemctl daemon-reload && + service docker restart +fi \ No newline at end of file