From d2c6362a59acbce154b35c957c1e9de7e688e474 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 13 Sep 2021 04:54:59 -0400 Subject: [PATCH] fix: start linked datastores when an app is started or restored This won't _also_ fix issues when an app is deployed as there isn't an exposed hook for it, but it should fix many other issues. For the app deployment problem, we'll need a new hook upstream. Refs dokku/dokku-redis#138 --- pre-restore | 36 ++++++++++++++++++++++++++++++++++++ pre-start | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100755 pre-restore create mode 100755 pre-start diff --git a/pre-restore b/pre-restore new file mode 100755 index 0000000..a03ad3c --- /dev/null +++ b/pre-restore @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions" +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +plugin-pre-restore() { + declare SCHEDULER="$1" APP="$2" + + if [[ "$SCHEDULER" != "docker-local" ]]; then + return + fi + + local SERVICES=$(ls "$PLUGIN_DATA_ROOT" 2>/dev/null) + for SERVICE in $SERVICES; do + if ! in_links_file "$SERVICE" "$APP"; then + continue + fi + + local status="$(service_status "$SERVICE")" + if [[ "$status" == "running" ]]; then + continue + fi + + if [[ "$status" == "restarting" ]]; then + dokku_log_warn "$PLUGIN_SERVICE service $SERVICE is restarting and may cause issues with linked app $APP" + continue + fi + + dokku_log_warn "$PLUGIN_SERVICE service $SERVICE is not running, issuing service start" + service_start "$SERVICE" + done +} + +plugin-pre-restore "$@" diff --git a/pre-start b/pre-start new file mode 100755 index 0000000..672de9c --- /dev/null +++ b/pre-start @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config" +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions" +source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +plugin-pre-start() { + declare APP="$1" + + local SERVICES=$(ls "$PLUGIN_DATA_ROOT" 2>/dev/null) + for SERVICE in $SERVICES; do + if ! in_links_file "$SERVICE" "$APP"; then + continue + fi + + local status="$(service_status "$SERVICE")" + if [[ "$status" == "running" ]]; then + continue + fi + + if [[ "$status" == "restarting" ]]; then + dokku_log_warn "$PLUGIN_SERVICE service $SERVICE is restarting and may cause issues with linked app $APP" + continue + fi + + dokku_log_warn "$PLUGIN_SERVICE service $SERVICE is not running, issuing service start" + service_start "$SERVICE" + done +} + +plugin-pre-start "$@"