From 1d85095ec863faaff2c113dedfc17c8b8ed82072 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 22:59:08 -0500 Subject: [PATCH 01/11] feat: allow dokku user to enable/disable nginx service --- plugins/nginx-vhosts/install | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index 8713fc128..e02958694 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -69,19 +69,19 @@ trigger-nginx-vhosts-install() { local mode="0440" case "$DOKKU_DISTRO" in debian | raspbian) - echo "%dokku ALL=(ALL) NOPASSWD:/usr/sbin/invoke-rc.d $NGINX_INIT_NAME reload, /usr/sbin/invoke-rc.d $NGINX_INIT_NAME start, /usr/sbin/invoke-rc.d $NGINX_INIT_NAME stop, $NGINX_BIN -t, ${NGINX_BIN} -t -c *" >"$NGINX_SUDOERS_FILE" + echo "%dokku ALL=(ALL) NOPASSWD:/usr/sbin/invoke-rc.d $NGINX_INIT_NAME enable, /usr/sbin/invoke-rc.d $NGINX_INIT_NAME disable, /usr/sbin/invoke-rc.d $NGINX_INIT_NAME reload, /usr/sbin/invoke-rc.d $NGINX_INIT_NAME start, /usr/sbin/invoke-rc.d $NGINX_INIT_NAME stop, $NGINX_BIN -t, ${NGINX_BIN} -t -c *" >"$NGINX_SUDOERS_FILE" ;; ubuntu) if [[ -x /usr/bin/sv ]]; then - echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/sv reload $NGINX_INIT_NAME, /usr/bin/sv start $NGINX_INIT_NAME, /usr/bin/sv stop $NGINX_INIT_NAME, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" + echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/sv enable $NGINX_INIT_NAME, /usr/bin/sv disable $NGINX_INIT_NAME, /usr/bin/sv reload $NGINX_INIT_NAME, /usr/bin/sv start $NGINX_INIT_NAME, /usr/bin/sv stop $NGINX_INIT_NAME, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" else - echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/$NGINX_INIT_NAME reload, /etc/init.d/$NGINX_INIT_NAME start, /etc/init.d/$NGINX_INIT_NAME stop, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" + echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/$NGINX_INIT_NAME enable, /etc/init.d/$NGINX_INIT_NAME disable, /etc/init.d/$NGINX_INIT_NAME reload, /etc/init.d/$NGINX_INIT_NAME start, /etc/init.d/$NGINX_INIT_NAME stop, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" fi ;; arch) - echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl reload $NGINX_INIT_NAME, /usr/bin/systemctl start $NGINX_INIT_NAME, /usr/bin/systemctl stop $NGINX_INIT_NAME, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" + echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl enable $NGINX_INIT_NAME, /usr/bin/systemctl disable $NGINX_INIT_NAME, /usr/bin/systemctl reload $NGINX_INIT_NAME, /usr/bin/systemctl start $NGINX_INIT_NAME, /usr/bin/systemctl stop $NGINX_INIT_NAME, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" ;; esac From 2946e6d632ee95d57eb378f24b73c04968b50ed3 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 22:59:39 -0500 Subject: [PATCH 02/11] fix: enable/disable nginx when calling nginx:start/nginx:stop --- plugins/nginx-vhosts/command-functions | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/nginx-vhosts/command-functions b/plugins/nginx-vhosts/command-functions index e13b31652..60657449f 100755 --- a/plugins/nginx-vhosts/command-functions +++ b/plugins/nginx-vhosts/command-functions @@ -117,6 +117,7 @@ cmd-nginx-stop() { touch "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" fn-nginx-vhosts-nginx-init-cmd "stop" + fn-nginx-vhosts-nginx-init-cmd "disable" } cmd-nginx-start() { @@ -125,6 +126,7 @@ cmd-nginx-start() { [[ "$1" == "$cmd" ]] && shift 1 rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" + fn-nginx-vhosts-nginx-init-cmd "enable" fn-nginx-vhosts-nginx-init-cmd "start" } From 5c205b9e27941aa9a6325a1609bd4999db9c8ac8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 23:00:37 -0500 Subject: [PATCH 03/11] feat: keep track of whether caddy and traefik should be stopped/started --- plugins/caddy-vhosts/command-functions | 2 ++ plugins/traefik-vhosts/command-functions | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugins/caddy-vhosts/command-functions b/plugins/caddy-vhosts/command-functions index d7409da1e..b763e693a 100755 --- a/plugins/caddy-vhosts/command-functions +++ b/plugins/caddy-vhosts/command-functions @@ -131,6 +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 + rm -f "${DOKKU_LIB_ROOT}/data/caddy/caddy.stopped" fn-caddy-template-compose-file "$TMP_COMPOSE_FILE" "$DOCKER_BIN" compose -f "$TMP_COMPOSE_FILE" -p caddy up -d --quiet-pull } @@ -147,6 +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 + touch "${DOKKU_LIB_ROOT}/data/caddy/caddy.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/traefik-vhosts/command-functions b/plugins/traefik-vhosts/command-functions index af59aaaef..44c38ce3f 100755 --- a/plugins/traefik-vhosts/command-functions +++ b/plugins/traefik-vhosts/command-functions @@ -135,6 +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 + rm -f "${DOKKU_LIB_ROOT}/data/traefik/traefik.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" @@ -153,6 +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 + touch "${DOKKU_LIB_ROOT}/data/traefik/traefik.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" From bde7b16a80c1f046ebd3c39ba6fec482b657adee Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 23:03:27 -0500 Subject: [PATCH 04/11] chore: reorder commands alphabetically --- plugins/nginx-vhosts/command-functions | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/nginx-vhosts/command-functions b/plugins/nginx-vhosts/command-functions index 60657449f..56bddc344 100755 --- a/plugins/nginx-vhosts/command-functions +++ b/plugins/nginx-vhosts/command-functions @@ -110,16 +110,6 @@ cmd-nginx-show-config() { cat "$DOKKU_ROOT/$APP/nginx.conf" } -cmd-nginx-stop() { - declare desc="stops the nginx server" - declare cmd="nginx:stop" - [[ "$1" == "$cmd" ]] && shift 1 - - touch "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" - fn-nginx-vhosts-nginx-init-cmd "stop" - fn-nginx-vhosts-nginx-init-cmd "disable" -} - cmd-nginx-start() { declare desc="starts the nginx server" declare cmd="nginx:start" @@ -130,6 +120,16 @@ cmd-nginx-start() { fn-nginx-vhosts-nginx-init-cmd "start" } +cmd-nginx-stop() { + declare desc="stops the nginx server" + declare cmd="nginx:stop" + [[ "$1" == "$cmd" ]] && shift 1 + + touch "${DOKKU_LIB_ROOT}/data/nginx-vhosts/nginx.stopped" + fn-nginx-vhosts-nginx-init-cmd "stop" + fn-nginx-vhosts-nginx-init-cmd "disable" +} + cmd-nginx-validate-config() { declare desc="validates and optionally cleans up invalid nginx configurations" declare cmd="nginx:validate-config" From b97a5c0c00cefe238f0dddf09c7ce24c3de9e1e9 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 23:03:46 -0500 Subject: [PATCH 05/11] feat: keep track of whether proxy implementation should be stopped or started --- plugins/caddy-vhosts/command-functions | 2 ++ plugins/nginx-vhosts/command-functions | 2 ++ plugins/traefik-vhosts/command-functions | 2 ++ 3 files changed, 6 insertions(+) diff --git a/plugins/caddy-vhosts/command-functions b/plugins/caddy-vhosts/command-functions index b763e693a..6ca5be82a 100755 --- a/plugins/caddy-vhosts/command-functions +++ b/plugins/caddy-vhosts/command-functions @@ -131,6 +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-caddy-template-compose-file "$TMP_COMPOSE_FILE" "$DOCKER_BIN" compose -f "$TMP_COMPOSE_FILE" -p caddy up -d --quiet-pull @@ -148,6 +149,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-caddy-template-compose-file "$TMP_COMPOSE_FILE" "$DOCKER_BIN" compose -f "$TMP_COMPOSE_FILE" -p caddy down --remove-orphans diff --git a/plugins/nginx-vhosts/command-functions b/plugins/nginx-vhosts/command-functions index 56bddc344..fdb73927f 100755 --- a/plugins/nginx-vhosts/command-functions +++ b/plugins/nginx-vhosts/command-functions @@ -115,6 +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-nginx-vhosts-nginx-init-cmd "enable" fn-nginx-vhosts-nginx-init-cmd "start" @@ -125,6 +126,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-nginx-vhosts-nginx-init-cmd "stop" fn-nginx-vhosts-nginx-init-cmd "disable" diff --git a/plugins/traefik-vhosts/command-functions b/plugins/traefik-vhosts/command-functions index 44c38ce3f..43f814a95 100755 --- a/plugins/traefik-vhosts/command-functions +++ b/plugins/traefik-vhosts/command-functions @@ -135,6 +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" touch "${DOKKU_LIB_ROOT}/data/traefik/traefik-acme.json" chmod 600 "${DOKKU_LIB_ROOT}/data/traefik/traefik-acme.json" @@ -154,6 +155,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" touch "${DOKKU_LIB_ROOT}/data/traefik/traefik-acme.json" chmod 600 "${DOKKU_LIB_ROOT}/data/traefik/traefik-acme.json" From 77fbd676bc45fc5971c1a2d7c21533799581f2ba Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 23:11:04 -0500 Subject: [PATCH 06/11] feat: start caddy/nginx/traefik prior to restoring applications This ensures routing works as expected. --- plugins/caddy-vhosts/pre-restore | 20 ++++++++++++++++++++ plugins/nginx-vhosts/pre-restore | 20 ++++++++++++++++++++ plugins/traefik-vhosts/pre-restore | 20 ++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100755 plugins/caddy-vhosts/pre-restore create mode 100755 plugins/nginx-vhosts/pre-restore create mode 100755 plugins/traefik-vhosts/pre-restore diff --git a/plugins/caddy-vhosts/pre-restore b/plugins/caddy-vhosts/pre-restore new file mode 100755 index 000000000..9b235c113 --- /dev/null +++ b/plugins/caddy-vhosts/pre-restore @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/caddy-vhosts/command-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +trigger-caddy-pre-restore() { + declare desc="pre-restore the caddy proxy" + declare trigger="install" + + if [[ ! -f "${DOKKU_LIB_ROOT}/data/caddy/caddy.started" ]]; then + return + fi + + if ! cmd-caddy-start; then + dokku_log_warn "Failed to restore caddy proxy, requests may not route as expected" + fi +} + +trigger-caddy-pre-restore "$@" diff --git a/plugins/nginx-vhosts/pre-restore b/plugins/nginx-vhosts/pre-restore new file mode 100755 index 000000000..fbfdc9bfc --- /dev/null +++ b/plugins/nginx-vhosts/pre-restore @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/command-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +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 + return + fi + + if ! cmd-nginx-start; then + dokku_log_warn "Failed to restore nginx proxy, requests may not route as expected" + fi +} + +trigger-nginx-pre-restore "$@" diff --git a/plugins/traefik-vhosts/pre-restore b/plugins/traefik-vhosts/pre-restore new file mode 100755 index 000000000..41b671b6b --- /dev/null +++ b/plugins/traefik-vhosts/pre-restore @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/traefik-vhosts/command-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +trigger-traefik-pre-restore() { + declare desc="pre-restore the traefik proxy" + declare trigger="install" + + if [[ ! -f "${DOKKU_LIB_ROOT}/data/traefik/traefik.started" ]]; then + return + fi + + if ! cmd-traefik-start; then + dokku_log_warn "Failed to restore traefik proxy, requests may not route as expected" + fi +} + +trigger-traefik-pre-restore "$@" From 6fed37b4084a4500b938f0067743d64a60272680 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 23:18:45 -0500 Subject: [PATCH 07/11] refactor: rename pre-restore trigger to scheduler-pre-restore This better reflects what the trigger does, and allows us to use the pre-restore trigger at the beginning of the ps:restore command. --- docs/appendices/0.29.0-migration-guide.md | 1 + docs/development/plugin-triggers.md | 21 ++++++++++++++++++- plugins/20_events/scheduler-pre-restore | 1 + plugins/ps/ps.go | 4 ++-- plugins/ps/subcommands.go | 4 ++++ .../{pre-restore => scheduler-pre-restore} | 8 +++---- 6 files changed, 32 insertions(+), 7 deletions(-) create mode 120000 plugins/20_events/scheduler-pre-restore rename plugins/scheduler-docker-local/{pre-restore => scheduler-pre-restore} (67%) diff --git a/docs/appendices/0.29.0-migration-guide.md b/docs/appendices/0.29.0-migration-guide.md index b02e83673..e262032ac 100644 --- a/docs/appendices/0.29.0-migration-guide.md +++ b/docs/appendices/0.29.0-migration-guide.md @@ -5,6 +5,7 @@ - The output of `run:detached` now uses the container name - eg. `node-js-app.run.1` - vs the container id. - The ID of `cron` tasks is now base36-encoded instead of base64-encoded. - The `nginx.conf.sigil` is now extracted when source code is extracted for a build and not from the built image. Users can specify alternative paths via the `nginx-conf-sigil-path` property of the `nginx` plugin. See the [nginx documentation](/docs/networking/proxies/nginx.md#customizing-the-nginx-configuration) for more information on how to configure the `nginx.conf.sigil` path for your application. +- The existing `pre-restore` hook has been renamed to `scheduler-pre-restore`. There is a new `pre-restore` hook that is triggered within the `ps:restore` command prior to restoring any apps. ## Removals diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 72293c3a3..eca55a663 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -1753,7 +1753,7 @@ APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG) - Description: Allows you to run commands before all containers are restored - Invoked by: `dokku ps:restore` -- Arguments: `$DOKKU_SCHEDULER $APP` +- Arguments: - Example: ```shell @@ -2187,6 +2187,25 @@ DOKKU_SCHEDULER="$1"; APP="$2"; # TODO ``` +### `scheduler-pre-restore` + +> Warning: The scheduler plugin trigger apis are under development and may change +> between minor releases until the 1.0 release. + +- Description: Allows you to run commands before an app is restored +- Invoked by: `dokku ps:restore` +- Arguments: `$DOKU_SCHEDULER $APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +DOKKU_SCHEDULER="$1"; APP="$2"; + +# TODO +``` + ### `scheduler-post-delete` > Warning: The scheduler plugin trigger apis are under development and may change diff --git a/plugins/20_events/scheduler-pre-restore b/plugins/20_events/scheduler-pre-restore new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/scheduler-pre-restore @@ -0,0 +1 @@ +hook \ No newline at end of file diff --git a/plugins/ps/ps.go b/plugins/ps/ps.go index 9d86e297b..0428edaa0 100644 --- a/plugins/ps/ps.go +++ b/plugins/ps/ps.go @@ -115,8 +115,8 @@ func RestartProcess(appName string, processName string) error { // Restore ensures an app that should be running is running on boot func Restore(appName string) error { scheduler := common.GetAppScheduler(appName) - if err := common.PlugnTrigger("pre-restore", []string{scheduler, appName}...); err != nil { - return fmt.Errorf("Error running pre-restore: %s", err) + if err := common.PlugnTrigger("scheduler-pre-restore", []string{scheduler, appName}...); err != nil { + return fmt.Errorf("Error running scheduler-pre-restore: %s", err) } common.LogInfo1("Clearing potentially invalid proxy configuration") diff --git a/plugins/ps/subcommands.go b/plugins/ps/subcommands.go index 442ffe062..02aeb2058 100644 --- a/plugins/ps/subcommands.go +++ b/plugins/ps/subcommands.go @@ -74,6 +74,10 @@ func CommandRestart(appName string, processName string, allApps bool, parallelCo // CommandRestore starts previously running apps e.g. after reboot func CommandRestore(appName string, allApps bool, parallelCount int) error { + if err := common.PlugnTrigger("pre-restore", []string{}...); err != nil { + return fmt.Errorf("Error running pre-restore: %s", err) + } + if allApps { if err := restorePrep(); err != nil { return err diff --git a/plugins/scheduler-docker-local/pre-restore b/plugins/scheduler-docker-local/scheduler-pre-restore similarity index 67% rename from plugins/scheduler-docker-local/pre-restore rename to plugins/scheduler-docker-local/scheduler-pre-restore index db4e8f34f..6a88d8ea4 100755 --- a/plugins/scheduler-docker-local/pre-restore +++ b/plugins/scheduler-docker-local/scheduler-pre-restore @@ -3,9 +3,9 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" -trigger-scheduler-docker-local-pre-restore() { - declare desc="scheduler-docker-local pre-restore plugin trigger" - declare trigger="pre-restore" +trigger-scheduler-docker-local-scheduler-pre-restore() { + declare desc="scheduler-docker-local scheduler-pre-restore plugin trigger" + declare trigger="scheduler-pre-restore" declare DOKKU_SCHEDULER="$1" if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then @@ -17,4 +17,4 @@ trigger-scheduler-docker-local-pre-restore() { "$DOCKER_BIN" container rm $("$DOCKER_BIN" container list --all --format "{{.Names}}" --filter "label=$DOKKU_CONTAINER_LABEL" --quiet | grep -E '(.+\..+\.[0-9]+\.[0-9]+$)') &>/dev/null || true } -trigger-scheduler-docker-local-pre-restore "$@" +trigger-scheduler-docker-local-scheduler-pre-restore "$@" From 5fed0c45ac88121aa0f8bebe19a7ed805b11a331 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 22 Nov 2022 23:29:34 -0500 Subject: [PATCH 08/11] 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 From a8bc8044e4994870689664d527250835b5eb4b38 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 28 Nov 2022 01:52:27 -0500 Subject: [PATCH 09/11] feat: switch to systemctl for interacting with the nginx init process --- docs/appendices/0.29.0-migration-guide.md | 1 + plugins/nginx-vhosts/install | 2 ++ plugins/nginx-vhosts/internal-functions | 2 ++ 3 files changed, 5 insertions(+) diff --git a/docs/appendices/0.29.0-migration-guide.md b/docs/appendices/0.29.0-migration-guide.md index e262032ac..ee8cb8578 100644 --- a/docs/appendices/0.29.0-migration-guide.md +++ b/docs/appendices/0.29.0-migration-guide.md @@ -6,6 +6,7 @@ - The ID of `cron` tasks is now base36-encoded instead of base64-encoded. - The `nginx.conf.sigil` is now extracted when source code is extracted for a build and not from the built image. Users can specify alternative paths via the `nginx-conf-sigil-path` property of the `nginx` plugin. See the [nginx documentation](/docs/networking/proxies/nginx.md#customizing-the-nginx-configuration) for more information on how to configure the `nginx.conf.sigil` path for your application. - The existing `pre-restore` hook has been renamed to `scheduler-pre-restore`. There is a new `pre-restore` hook that is triggered within the `ps:restore` command prior to restoring any apps. +- Nginx init commands are now performed via systemctl on Ubuntu systems when `/usr/bin/systemctl` is available. ## Removals diff --git a/plugins/nginx-vhosts/install b/plugins/nginx-vhosts/install index e104494af..e5f0e7af4 100755 --- a/plugins/nginx-vhosts/install +++ b/plugins/nginx-vhosts/install @@ -75,6 +75,8 @@ trigger-nginx-vhosts-install() { ubuntu) if [[ -x /usr/bin/sv ]]; then echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/sv enable $NGINX_INIT_NAME, /usr/bin/sv disable $NGINX_INIT_NAME, /usr/bin/sv reload $NGINX_INIT_NAME, /usr/bin/sv start $NGINX_INIT_NAME, /usr/bin/sv stop $NGINX_INIT_NAME, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" + elif [[ -x /usr/bin/systemctl ]]; then + echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl enable $NGINX_INIT_NAME, /usr/bin/systemctl disable $NGINX_INIT_NAME, /usr/bin/systemctl reload $NGINX_INIT_NAME, /usr/bin/systemctl start $NGINX_INIT_NAME, /usr/bin/systemctl stop $NGINX_INIT_NAME, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" else echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/$NGINX_INIT_NAME enable, /etc/init.d/$NGINX_INIT_NAME disable, /etc/init.d/$NGINX_INIT_NAME reload, /etc/init.d/$NGINX_INIT_NAME start, /etc/init.d/$NGINX_INIT_NAME stop, $NGINX_BIN -t, $NGINX_BIN -t -c *" >"$NGINX_SUDOERS_FILE" fi diff --git a/plugins/nginx-vhosts/internal-functions b/plugins/nginx-vhosts/internal-functions index e8eba5f71..ff00477b7 100755 --- a/plugins/nginx-vhosts/internal-functions +++ b/plugins/nginx-vhosts/internal-functions @@ -132,6 +132,8 @@ fn-nginx-vhosts-nginx-init-cmd() { # support docker-based installations if [[ -x /usr/bin/sv ]]; then sudo /usr/bin/sv "$CMD" "$NGINX_INIT_NAME" + elif [[ -x /usr/bin/systemctl ]]; then + sudo /usr/bin/systemctl "$CMD" "$NGINX_INIT_NAME" else sudo "/etc/init.d/$NGINX_INIT_NAME" "$CMD" fi From e2d215ab4faee6fd4765cf4fd993c3069d82e7fa Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 30 Nov 2022 01:43:14 -0500 Subject: [PATCH 10/11] fix: do not run enable/disable when using init.d init.d doesn't support these two commands, causing nginx:stop/nginx:start to fail. --- plugins/nginx-vhosts/internal-functions | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/nginx-vhosts/internal-functions b/plugins/nginx-vhosts/internal-functions index ff00477b7..7a6ae1e79 100755 --- a/plugins/nginx-vhosts/internal-functions +++ b/plugins/nginx-vhosts/internal-functions @@ -134,6 +134,8 @@ fn-nginx-vhosts-nginx-init-cmd() { sudo /usr/bin/sv "$CMD" "$NGINX_INIT_NAME" elif [[ -x /usr/bin/systemctl ]]; then sudo /usr/bin/systemctl "$CMD" "$NGINX_INIT_NAME" + elif [[ "$CMD" == "enable" ]] || [[ "$CMD" == "disable" ]]; then + dokku_log_warn "Running $CMD is not possible for init.d managed services" else sudo "/etc/init.d/$NGINX_INIT_NAME" "$CMD" fi From 7ec555f6178d1b12a3b5ed462e96a6943d937ccd Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 1 Dec 2022 00:27:21 -0500 Subject: [PATCH 11/11] fix: properly test priority It is no longer part of the service name. --- tests/unit/traefik.bats | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/unit/traefik.bats b/tests/unit/traefik.bats index 5901a01e3..4c3b0e82c 100644 --- a/tests/unit/traefik.bats +++ b/tests/unit/traefik.bats @@ -104,6 +104,12 @@ teardown() { echo "output: $output" echo "status: $status" assert_output "5000" + + run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"traefik.http.routers.$TEST_APP-web-http.priority\" }}'" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "12345" } @test "(traefik) ssl" { @@ -112,11 +118,6 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "dokku traefik:set $TEST_APP priority 12345" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku proxy:set $TEST_APP traefik" echo "output: $output" echo "status: $status" @@ -127,13 +128,13 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"traefik.http.services.$TEST_APP-web-http-12345.loadbalancer.server.port\" }}'" + run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"traefik.http.services.$TEST_APP-web-http.loadbalancer.server.port\" }}'" echo "output: $output" echo "status: $status" assert_success assert_output "5000" - run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"traefik.http.services.$TEST_APP-web-https-12345.loadbalancer.server.port\" }}'" + run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"traefik.http.services.$TEST_APP-web-https.loadbalancer.server.port\" }}'" echo "output: $output" echo "status: $status" assert_success @@ -164,13 +165,13 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"traefik.http.services.$TEST_APP-web-http-12345.loadbalancer.server.port\" }}'" + run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"traefik.http.services.$TEST_APP-web-http.loadbalancer.server.port\" }}'" echo "output: $output" echo "status: $status" assert_success assert_output "5000" - run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"traefik.http.services.$TEST_APP-web-https-12345.loadbalancer.server.port\" }}'" + run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"traefik.http.services.$TEST_APP-web-https.loadbalancer.server.port\" }}'" echo "output: $output" echo "status: $status" assert_success