From 5fed0c45ac88121aa0f8bebe19a7ed805b11a331 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 23:29:34 -0500 Subject: [PATCH] refactor: use the properties system instead of the data dir for tracking whether a proxy should be stopped or started --- plugins/caddy-vhosts/command-functions | 6 ++---- plugins/caddy-vhosts/pre-restore | 2 +- plugins/nginx-vhosts/command-functions | 6 ++---- plugins/nginx-vhosts/install | 7 ++++++- plugins/nginx-vhosts/pre-restore | 2 +- plugins/traefik-vhosts/command-functions | 6 ++---- plugins/traefik-vhosts/pre-restore | 2 +- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/plugins/caddy-vhosts/command-functions b/plugins/caddy-vhosts/command-functions index 6ca5be82a..9636ef451 100755 --- a/plugins/caddy-vhosts/command-functions +++ b/plugins/caddy-vhosts/command-functions @@ -131,8 +131,7 @@ cmd-caddy-start() { local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT - touch "${DOKKU_LIB_ROOT}/data/caddy/caddy.started" - rm -f "${DOKKU_LIB_ROOT}/data/caddy/caddy.stopped" + fn-plugin-property-write "caddy" "--global" "proxy-status" "started" fn-caddy-template-compose-file "$TMP_COMPOSE_FILE" "$DOCKER_BIN" compose -f "$TMP_COMPOSE_FILE" -p caddy up -d --quiet-pull } @@ -149,8 +148,7 @@ cmd-caddy-stop() { local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT - rm -f "${DOKKU_LIB_ROOT}/data/caddy/caddy.started" - touch "${DOKKU_LIB_ROOT}/data/caddy/caddy.stopped" + fn-plugin-property-write "caddy" "--global" "proxy-status" "stopped" fn-caddy-template-compose-file "$TMP_COMPOSE_FILE" "$DOCKER_BIN" compose -f "$TMP_COMPOSE_FILE" -p caddy down --remove-orphans } diff --git a/plugins/caddy-vhosts/pre-restore b/plugins/caddy-vhosts/pre-restore index 9b235c113..78f5cae59 100755 --- a/plugins/caddy-vhosts/pre-restore +++ b/plugins/caddy-vhosts/pre-restore @@ -8,7 +8,7 @@ trigger-caddy-pre-restore() { declare desc="pre-restore the caddy proxy" declare trigger="install" - if [[ ! -f "${DOKKU_LIB_ROOT}/data/caddy/caddy.started" ]]; then + if [[ "$(fn-plugin-property-get "caddy" "--global" "proxy-status")" == "stopped" ]]; then return fi diff --git a/plugins/nginx-vhosts/command-functions b/plugins/nginx-vhosts/command-functions index fdb73927f..215aaccc1 100755 --- a/plugins/nginx-vhosts/command-functions +++ b/plugins/nginx-vhosts/command-functions @@ -115,8 +115,7 @@ cmd-nginx-start() { declare cmd="nginx:start" [[ "$1" == "$cmd" ]] && shift 1 - touch "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.started" - rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" + fn-plugin-property-write "nginx" "--global" "proxy-status" "started" fn-nginx-vhosts-nginx-init-cmd "enable" fn-nginx-vhosts-nginx-init-cmd "start" } @@ -126,8 +125,7 @@ cmd-nginx-stop() { declare cmd="nginx:stop" [[ "$1" == "$cmd" ]] && shift 1 - rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.started" - touch "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" + fn-plugin-property-write "nginx" "--global" "proxy-status" "stopped" fn-nginx-vhosts-nginx-init-cmd "stop" fn-nginx-vhosts-nginx-init-cmd "disable" } diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index e02958694..e104494af 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -130,10 +130,15 @@ trigger-nginx-vhosts-install() { fn-nginx-vhosts-migrate-env-vars fn-nginx-vhosts-migrate-nginx-conf-sigil + if [[ -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" ]]; then + rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" + fn-plugin-property-write "nginx" "--global" "proxy-status" "stopped" + fi + # avoid failing runit init calls on install # the runit binaries are not yet available during dockerfile building # and therefore both these calls will fail - if [[ ! -x /usr/bin/sv ]] && [[ ! -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" ]]; then + if [[ ! -x /usr/bin/sv ]] && [[ "$(fn-plugin-property-get "nginx" "--global" "proxy-status")" != "stopped" ]]; then fn-nginx-vhosts-nginx-init-cmd start || fn-nginx-vhosts-nginx-init-cmd reload fi } diff --git a/plugins/nginx-vhosts/pre-restore b/plugins/nginx-vhosts/pre-restore index fbfdc9bfc..b7de63b37 100755 --- a/plugins/nginx-vhosts/pre-restore +++ b/plugins/nginx-vhosts/pre-restore @@ -8,7 +8,7 @@ trigger-nginx-pre-restore() { declare desc="pre-restore the nginx proxy" declare trigger="install" - if [[ ! -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.started" ]]; then + if [[ "$(fn-plugin-property-get "nginx" "--global" "proxy-status")" == "stopped" ]]; then return fi diff --git a/plugins/traefik-vhosts/command-functions b/plugins/traefik-vhosts/command-functions index 43f814a95..6136fd178 100755 --- a/plugins/traefik-vhosts/command-functions +++ b/plugins/traefik-vhosts/command-functions @@ -135,8 +135,7 @@ cmd-traefik-start() { local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT - touch "${DOKKU_LIB_ROOT}/data/traefik/traefik.started" - rm -f "${DOKKU_LIB_ROOT}/data/traefik/traefik.stopped" + fn-plugin-property-write "traefik" "--global" "proxy-status" "started" touch "${DOKKU_LIB_ROOT}/data/traefik/traefik-acme.json" chmod 600 "${DOKKU_LIB_ROOT}/data/traefik/traefik-acme.json" fn-traefik-template-compose-file "$TMP_COMPOSE_FILE" @@ -155,8 +154,7 @@ cmd-traefik-stop() { local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX") trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT - rm -f "${DOKKU_LIB_ROOT}/data/traefik/traefik.started" - touch "${DOKKU_LIB_ROOT}/data/traefik/traefik.stopped" + fn-plugin-property-write "traefik" "--global" "proxy-status" "stopped" touch "${DOKKU_LIB_ROOT}/data/traefik/traefik-acme.json" chmod 600 "${DOKKU_LIB_ROOT}/data/traefik/traefik-acme.json" fn-traefik-template-compose-file "$TMP_COMPOSE_FILE" diff --git a/plugins/traefik-vhosts/pre-restore b/plugins/traefik-vhosts/pre-restore index 41b671b6b..7b522d76f 100755 --- a/plugins/traefik-vhosts/pre-restore +++ b/plugins/traefik-vhosts/pre-restore @@ -8,7 +8,7 @@ trigger-traefik-pre-restore() { declare desc="pre-restore the traefik proxy" declare trigger="install" - if [[ ! -f "${DOKKU_LIB_ROOT}/data/traefik/traefik.started" ]]; then + if [[ "$(fn-plugin-property-get "traefik" "--global" "proxy-status")" == "stopped" ]]; then return fi