From bb60a4ce49376b957f4c5b93dde97bf70b75e1b2 Mon Sep 17 00:00:00 2001 From: Martin Honermeyer Date: Sat, 3 Jun 2017 16:39:22 +0200 Subject: [PATCH 1/2] Only use "detach" option w/ docker >= 17.05 --- shepherd | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/shepherd b/shepherd index 2de7626..d4d8100 100755 --- a/shepherd +++ b/shepherd @@ -1,8 +1,15 @@ #!/bin/bash set -euo pipefail +server_version() { + docker version -f "{{.Server.Version}}" +} + update_services() { local blacklist="$1" + local supports_detach_option=$2 + local detach_option="" + [ $supports_detach_option = true ] && detach_option="--detach=false" for service in $(IFS="\n" docker service ls --quiet); do local name image_with_digest image @@ -11,19 +18,26 @@ update_services() { image_with_digest="$(docker service inspect "$service" -f '{{.Spec.TaskTemplate.ContainerSpec.Image}}')" image=$(echo "$image_with_digest" | cut -d@ -f1) echo "Updating service $name with image $image" - docker service update "$service" --detach=false --image="$image" > /dev/null + docker service update "$service" $detach_option --image="$image" > /dev/null fi done } main() { - local blacklist="${BLACKLIST_SERVICES:-}" + local blacklist supports_detach_option=false + blacklist="${BLACKLIST_SERVICES:-}" + + if [[ "$(server_version)" > "17.05" ]]; then + supports_detach_option=true + echo "Enabling synchronous service updates" + fi + [[ "$blacklist" != "" ]] && echo "Excluding services: $blacklist" while true; do - update_services "${blacklist}" - echo "Sleeping ${SLEEP_TIME} before next update" - sleep "${SLEEP_TIME}" + update_services "$blacklist" "$supports_detach_option" + echo "Sleeping $SLEEP_TIME before next update" + sleep "$SLEEP_TIME" done } From 43138d8b9334fbead1d0351cb6520db5ee97a929 Mon Sep 17 00:00:00 2001 From: Martin Honermeyer Date: Sat, 3 Jun 2017 16:43:58 +0200 Subject: [PATCH 2/2] Do not fail if SLEEP_TIME is missing --- shepherd | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/shepherd b/shepherd index d4d8100..cb15dce 100755 --- a/shepherd +++ b/shepherd @@ -24,20 +24,24 @@ update_services() { } main() { - local blacklist supports_detach_option=false + local blacklist sleep_time supports_detach_option blacklist="${BLACKLIST_SERVICES:-}" + sleep_time="${SLEEP_TIME:-5m}" + supports_detach_option=false if [[ "$(server_version)" > "17.05" ]]; then supports_detach_option=true echo "Enabling synchronous service updates" + else + supports_detach_option=false fi [[ "$blacklist" != "" ]] && echo "Excluding services: $blacklist" while true; do update_services "$blacklist" "$supports_detach_option" - echo "Sleeping $SLEEP_TIME before next update" - sleep "$SLEEP_TIME" + echo "Sleeping $sleep_time before next update" + sleep "$sleep_time" done }