From 9e4c161416f472c6c106c23797b0a91d70085ded Mon Sep 17 00:00:00 2001 From: Chai Feng Date: Wed, 3 Oct 2018 09:08:28 +0800 Subject: [PATCH] add service sub-command --- ufw-docker | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ufw-docker b/ufw-docker index 0c81bbd..6e7f57d 100755 --- a/ufw-docker +++ b/ufw-docker @@ -99,6 +99,24 @@ function ufw-docker--instance-name() { } | remove_blank_lines } +function ufw-docker--service() { + service_action="${1:-help}" + case "$service_action" in + allow) + shift || true + service_id_or_name="${1:?Missing swarm service name}" + service_name="$(docker service inspect "$service_id_or_name" --format '{{.Spec.Name}}')" + + service_port="${2:-}" + + die "ufw-docker--service-${service_action}" "${service_name}" "${service_port}" + ;; + *) + ufw-docker--help + ;; + esac +} + function ufw-docker--install() { if ! grep "^# BEGIN UFW AND DOCKER\$" /etc/ufw/after.rules &>/dev/null; then err "Back up /etc/ufw/after.rules" @@ -198,6 +216,10 @@ case "$UFW_ACTION" in "ufw-docker--$UFW_ACTION" "$INSTANCE_NAME" "$INSTANCE_PORT" "$PROTO" ;; + service) + shift || true + "ufw-docker--$UFW_ACTION" "$@" + ;; status|install) ufw-docker--"$UFW_ACTION" ;;