add service sub-command

This commit is contained in:
Chai Feng 2018-10-03 09:08:28 +08:00
parent 89b3aaa5aa
commit 9e4c161416
No known key found for this signature in database
GPG Key ID: 2DCD9A24E523FFD2

View File

@ -99,6 +99,24 @@ function ufw-docker--instance-name() {
} | remove_blank_lines } | 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() { function ufw-docker--install() {
if ! grep "^# BEGIN UFW AND DOCKER\$" /etc/ufw/after.rules &>/dev/null; then if ! grep "^# BEGIN UFW AND DOCKER\$" /etc/ufw/after.rules &>/dev/null; then
err "Back up /etc/ufw/after.rules" err "Back up /etc/ufw/after.rules"
@ -198,6 +216,10 @@ case "$UFW_ACTION" in
"ufw-docker--$UFW_ACTION" "$INSTANCE_NAME" "$INSTANCE_PORT" "$PROTO" "ufw-docker--$UFW_ACTION" "$INSTANCE_NAME" "$INSTANCE_PORT" "$PROTO"
;; ;;
service)
shift || true
"ufw-docker--$UFW_ACTION" "$@"
;;
status|install) status|install)
ufw-docker--"$UFW_ACTION" ufw-docker--"$UFW_ACTION"
;; ;;