Skip to content

Commit bb60a4c

Browse files
committed
Only use "detach" option w/ docker >= 17.05
1 parent 31f6ff3 commit bb60a4c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

shepherd

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
#!/bin/bash
22
set -euo pipefail
33

4+
server_version() {
5+
docker version -f "{{.Server.Version}}"
6+
}
7+
48
update_services() {
59
local blacklist="$1"
10+
local supports_detach_option=$2
11+
local detach_option=""
12+
[ $supports_detach_option = true ] && detach_option="--detach=false"
613

714
for service in $(IFS="\n" docker service ls --quiet); do
815
local name image_with_digest image
@@ -11,19 +18,26 @@ update_services() {
1118
image_with_digest="$(docker service inspect "$service" -f '{{.Spec.TaskTemplate.ContainerSpec.Image}}')"
1219
image=$(echo "$image_with_digest" | cut -d@ -f1)
1320
echo "Updating service $name with image $image"
14-
docker service update "$service" --detach=false --image="$image" > /dev/null
21+
docker service update "$service" $detach_option --image="$image" > /dev/null
1522
fi
1623
done
1724
}
1825

1926
main() {
20-
local blacklist="${BLACKLIST_SERVICES:-}"
27+
local blacklist supports_detach_option=false
28+
blacklist="${BLACKLIST_SERVICES:-}"
29+
30+
if [[ "$(server_version)" > "17.05" ]]; then
31+
supports_detach_option=true
32+
echo "Enabling synchronous service updates"
33+
fi
34+
2135
[[ "$blacklist" != "" ]] && echo "Excluding services: $blacklist"
2236

2337
while true; do
24-
update_services "${blacklist}"
25-
echo "Sleeping ${SLEEP_TIME} before next update"
26-
sleep "${SLEEP_TIME}"
38+
update_services "$blacklist" "$supports_detach_option"
39+
echo "Sleeping $SLEEP_TIME before next update"
40+
sleep "$SLEEP_TIME"
2741
done
2842
}
2943

0 commit comments

Comments
 (0)