Skip to content

Commit

Permalink
fix: docker service update with --detach=false hangs on services wi… (
Browse files Browse the repository at this point in the history
#104)

* fix: docker service update with `--detach=false` hangs on services with 0 tasks

read more here: docker/cli#627

* refactor: use $(...) notation instead of legacy backticks `...`

* refactor: `tasks_num` variable renamed to `num_tasks`

* refactor: use `-f` for filtering service by name
  • Loading branch information
AliRezaBeitari authored Jul 6, 2023
1 parent a947a6b commit b7c010a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions shepherd
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ update_services() {
else
logger "Trying to update service $name with image $image" "true"

num_tasks=$(docker service ls -f "name=$name" | awk 'NR==2{print $4}')
if [[ $num_tasks = 0/* ]]; then
detach_option="--detach=true"
fi

# shellcheck disable=SC2086
if ! timeout "${TIMEOUT:-300}" docker "${config_flag[@]}" service update "$name" $detach_option $registry_auth $no_resolve_image_flag ${UPDATE_OPTIONS} --image="$image" > /dev/null; then
logger "Service $name update failed on $hostname!"
Expand Down

2 comments on commit b7c010a

@shizunge
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the service is in replicated mode, you may also want to add --replicas=0 to avoid starting a task after updating.

@shizunge
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some additional comments after comparing this to my own fix.

  1. Besides --filter to the docker service ls command, you can also add --format {{.Replicas}} to avoid using the awk.
  2. Have you test it with Replicated Job, which is different from Replicated. The output of the Replicas column looks like 1/1 (3/5 completed). Since you are using awk, I guess it may work.

Please sign in to comment.