Implement restart-policy handling. Closes #1734

Applications without a restart-policy will have their policies set to `on-failure:10`. Users can completely unset the restart-policy using the `docker-options` plugin, though this will be equivalent to setting it explicitly to `no`.

Restart policies must be explicitly set, and the following are all valid:

- no
- unless-stopped
- always
- on-failure
- on-failure:NUMBER
This commit is contained in:
Jose Diaz-Gonzalez
2016-07-02 17:17:17 -04:00
parent b4481cfd3a
commit 59c9207797
6 changed files with 98 additions and 0 deletions

View 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"
echo "$APP restart-policy:"
get_restart_policies "$(get_phase_file_path "$passed_phases")"
}
ps_restart_policy_cmd "$@"

View 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 "$@"