Skip to content

Commit 0cee1cb

Browse files
authored
Merge pull request #5 from djmaze/0.2-fixes
Fixes for 0.2
2 parents 31f6ff3 + 43138d8 commit 0cee1cb

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

shepherd

Lines changed: 23 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,30 @@ 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 sleep_time supports_detach_option
28+
blacklist="${BLACKLIST_SERVICES:-}"
29+
sleep_time="${SLEEP_TIME:-5m}"
30+
31+
supports_detach_option=false
32+
if [[ "$(server_version)" > "17.05" ]]; then
33+
supports_detach_option=true
34+
echo "Enabling synchronous service updates"
35+
else
36+
supports_detach_option=false
37+
fi
38+
2139
[[ "$blacklist" != "" ]] && echo "Excluding services: $blacklist"
2240

2341
while true; do
24-
update_services "${blacklist}"
25-
echo "Sleeping ${SLEEP_TIME} before next update"
26-
sleep "${SLEEP_TIME}"
42+
update_services "$blacklist" "$supports_detach_option"
43+
echo "Sleeping $sleep_time before next update"
44+
sleep "$sleep_time"
2745
done
2846
}
2947

0 commit comments

Comments
 (0)