Skip to content

Commit

Permalink
Simplify checking conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
brablc committed Jun 2, 2024
1 parent e2da847 commit 8fd2e0b
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,9 @@ while read service; do
network_alias=$(get_service $service | jq -r '.Spec.TaskTemplate.Networks[].Aliases[]' | sort | head -1)

echo $ports | sed 's/,/\n/g' | while read port; do
read service_id replicas < <(get_service $service | jq -r '"\(.ID) \(.Spec.Mode.Replicated.Replicas)"')
test "$replicas" != "0" || continue

if [[ $replicas == "null" ]]; then
filter=$(echo '{"service":["'$service_id'"], "desired-state":["running"]}' | jq -s -R -r @uri)
read state message exit_code < <(curl -s --unix-socket $sock "$url/tasks?filters=$filter" | jq -r '.[] | "\(.Status.State) \(.Status.Message) \(.ContainerStatus.ExitCode)"' | grep running | head -1)

test "$state" == "running" || break
read service_id mode replicas < <(get_service $service | jq -r '"\(.ID) \(.Spec.Mode | keys[0]) \(.Spec.Mode.Replicated.Replicas)"')
if [[ $mode == "Global" || ( $mode == "Replicated" && "$replicas" != "0" ) ]]; then
echo "$service $network_alias $port"
fi

echo "$service $network_alias $port"

done
done < <(get_services)

0 comments on commit 8fd2e0b

Please sign in to comment.