From c750f5a768e74de0ec38db91706c2ec03b43578e Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Thu, 30 Jul 2015 16:00:53 -0400 Subject: [PATCH 1/2] Allow stop/kill to continue in the event that it cannot stop or kill one of the old containers. Also actually attempt to kill if stop has a bad exit code. --- dokku | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dokku b/dokku index a32bd815c..98cb9679d 100755 --- a/dokku +++ b/dokku @@ -178,8 +178,12 @@ case "$1" in trap '' INT HUP sleep $WAIT for oldid in $oldids; do - docker stop $oldid &> /dev/null - docker kill $oldid &> /dev/null # force a kill as docker seems to not send SIGKILL as the docs would indicate + # Attempt to stop, if that fails, then force a kill as docker seems + # to not send SIGKILL as the docs would indicate. If that fails, move + # on to the next. + docker stop $oldid \ + || docker kill $oldid \ + || : # Always continue in case we have multiple to kill done ) & disown -a # Use trap since disown/nohup don't seem to keep child alive From b2949d2199d81d6e4c48628e28e8edc71bbbc92e Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 10 Sep 2015 08:47:48 -0700 Subject: [PATCH 2/2] log when killing old app container(s) fails --- docs/development/pluginhooks.md | 16 ++++++++++++++++ dokku | 2 +- plugins/20_events/retire-container-failed | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) create mode 120000 plugins/20_events/retire-container-failed diff --git a/docs/development/pluginhooks.md b/docs/development/pluginhooks.md index 957e77584..63287f670 100644 --- a/docs/development/pluginhooks.md +++ b/docs/development/pluginhooks.md @@ -664,3 +664,19 @@ APP="$1"; IMAGE_TAG="$2" some code to remove a docker hub tag because it's not implemented in the CLI.... ``` + +### `retire-container-failed` + +- Description: Allows you to run commands if/when retiring old containers has failed +- Invoked by: `dokku deploy` +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +APP="$1"; HOSTNAME=$(hostname -s) + +mail -s "$APP containers on $HOSTNAME failed to retire" ops@co.com +``` diff --git a/dokku b/dokku index a5b219a04..802e88538 100755 --- a/dokku +++ b/dokku @@ -186,7 +186,7 @@ case "$1" in # on to the next. docker stop $oldid \ || docker kill $oldid \ - || : # Always continue in case we have multiple to kill + || pluginhook retire-container-failed $APP # Trigger pluginhook for event logging done ) & disown -a # Use trap since disown/nohup don't seem to keep child alive diff --git a/plugins/20_events/retire-container-failed b/plugins/20_events/retire-container-failed new file mode 120000 index 000000000..5178a749f --- /dev/null +++ b/plugins/20_events/retire-container-failed @@ -0,0 +1 @@ +hook \ No newline at end of file