mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
Merge pull request #2290 from dokku/1734-restart-policies
Implement restart-policy handling
This commit is contained in:
@@ -16,6 +16,8 @@ case "$1" in
|
||||
ps:restart <app>, Restart app container(s)
|
||||
ps:restartall, Restart all deployed app containers
|
||||
ps:restore, Start previously running apps e.g. after reboot
|
||||
ps:restart-policy <app>, Shows the restart-policy for an app
|
||||
ps:set-restart-policy <app> <policy>, Sets app restart-policy
|
||||
help_content
|
||||
}
|
||||
|
||||
|
||||
@@ -165,3 +165,15 @@ ps_scale() {
|
||||
release_and_deploy "$APP" "$IMAGE_TAG"
|
||||
fi
|
||||
}
|
||||
|
||||
get_raw_restart_policies() {
|
||||
declare desc="strips docker options and prints raw restart policies"
|
||||
local -r phase_file_path=$1
|
||||
[[ -r "$phase_file_path" ]] && sed -e '/^--restart=/!d' < "$phase_file_path"
|
||||
}
|
||||
|
||||
get_restart_policies() {
|
||||
declare desc="strips docker options and prints restart policies"
|
||||
local -r phase_file_path=$1
|
||||
get_raw_restart_policies "$phase_file_path" | sed -e 's/^--restart=//g'
|
||||
}
|
||||
|
||||
21
plugins/ps/install
Executable file
21
plugins/ps/install
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/docker-options/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||
|
||||
set_default_restart_policies() {
|
||||
declare desc="set the default restart policy for all applications if there is not one already set"
|
||||
local APPS="$(dokku_apps)"
|
||||
local APP
|
||||
|
||||
for APP in $APPS; do
|
||||
local RESTART_POLICIES=$(get_restart_policies "$(get_phase_file_path "deploy")")
|
||||
if [[ -z "$RESTART_POLICIES" ]]; then
|
||||
local passed_phases=(deploy)
|
||||
add_passed_docker_option passed_phases[@] "--restart=on-failure:10"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
set_default_restart_policies "$@"
|
||||
16
plugins/ps/post-create
Executable file
16
plugins/ps/post-create
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/docker-options/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||
|
||||
ps_post_create() {
|
||||
declare desc="ps post-create plugin trigger"
|
||||
local trigger="ps_post_create"
|
||||
local APP="$1"
|
||||
|
||||
local passed_phases=(deploy)
|
||||
add_passed_docker_option passed_phases[@] "--restart=on-failure:10"
|
||||
}
|
||||
|
||||
ps_post_create "$@"
|
||||
18
plugins/ps/subcommands/restart-policy
Executable file
18
plugins/ps/subcommands/restart-policy
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/docker-options/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||
|
||||
ps_restart_policy_cmd() {
|
||||
declare desc="shows the restart-policy for an app"
|
||||
local cmd="ps:restart-policy"
|
||||
local passed_phases="deploy"
|
||||
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||
verify_app_name "$2" && local APP="$2"
|
||||
|
||||
dokku_log_info2_quiet "$APP restart-policy:"
|
||||
get_restart_policies "$(get_phase_file_path "$passed_phases")"
|
||||
}
|
||||
|
||||
ps_restart_policy_cmd "$@"
|
||||
31
plugins/ps/subcommands/set-restart-policy
Executable file
31
plugins/ps/subcommands/set-restart-policy
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/docker-options/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||
|
||||
ps_set_restart_policy_cmd() {
|
||||
declare desc="sets app restart-policy"
|
||||
local cmd="ps:set-restart-policy"
|
||||
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||
verify_app_name "$2" && local APP="$2"
|
||||
local RESTART_POLICY="$3"
|
||||
local RE_RESTART_POLICY="^(no|unless-stopped|always|on-failure(:[1-9][0-9]*)?)$"
|
||||
|
||||
if [[ ! "$RESTART_POLICY" =~ $RE_RESTART_POLICY ]]; then
|
||||
dokku_log_fail "Please specify an valid restart policy matching the following regex: ${RE_RESTART_POLICY}"
|
||||
fi
|
||||
|
||||
local RESTART_POLICIES=$(get_raw_restart_policies "$(get_phase_file_path "deploy")")
|
||||
local passed_phases=(deploy)
|
||||
|
||||
for policy in $RESTART_POLICIES; do
|
||||
remove_passed_docker_option passed_phases[@] "$policy"
|
||||
done
|
||||
|
||||
dokku_log_info1_quiet "Setting restart policy: ${RESTART_POLICY}"
|
||||
local passed_phases=(deploy)
|
||||
add_passed_docker_option passed_phases[@] "--restart=${RESTART_POLICY}"
|
||||
}
|
||||
|
||||
ps_set_restart_policy_cmd "$@"
|
||||
Reference in New Issue
Block a user