feat: add ability to scope retire call to a single app
Also cleanup the log output a bit for the ps:retire command.
This commit is contained in:
1 parent
7a564f3185
commit
9e18736475
5 files changed
+32
-14
No files matched your search
@@ -2169,14 +2169,14 @@ CONTAINER_ID="$2";
|
|||||||
|
|
||||||
- Description: Allows you to run scheduler commands when containers should be force retired from the system
|
- Description: Allows you to run scheduler commands when containers should be force retired from the system
|
||||||
- Invoked by: `dokku run`
|
- Invoked by: `dokku run`
|
||||||
- Arguments: `$DOKKU_SCHEDULER`
|
- Arguments: `$DOKKU_SCHEDULER $APP`
|
||||||
- Example:
|
- Example:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
DOKKU_SCHEDULER="$1";
|
DOKKU_SCHEDULER="$1"; APP="$2";
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ func main() {
|
|||||||
case "retire":
|
case "retire":
|
||||||
args := flag.NewFlagSet("ps:retire", flag.ExitOnError)
|
args := flag.NewFlagSet("ps:retire", flag.ExitOnError)
|
||||||
args.Parse(os.Args[2:])
|
args.Parse(os.Args[2:])
|
||||||
err = ps.CommandRetire()
|
appName := args.Arg(0)
|
||||||
|
err = ps.CommandRetire(appName)
|
||||||
case "scale":
|
case "scale":
|
||||||
args := flag.NewFlagSet("ps:scale", flag.ExitOnError)
|
args := flag.NewFlagSet("ps:scale", flag.ExitOnError)
|
||||||
skipDeploy := args.Bool("skip-deploy", false, "--skip-deploy: skip deploy of the app")
|
skipDeploy := args.Bool("skip-deploy", false, "--skip-deploy: skip deploy of the app")
|
||||||
|
|||||||
@@ -93,9 +93,14 @@ func CommandRestore(appName string, allApps bool, parallelCount int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CommandRetire ensures old containers are retired
|
// CommandRetire ensures old containers are retired
|
||||||
func CommandRetire() error {
|
func CommandRetire(appName string) error {
|
||||||
lockFile := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "ps", "retire")
|
lockFile := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "ps", "retire")
|
||||||
scheduler := common.GetGlobalScheduler()
|
scheduler := ""
|
||||||
|
if appName == "" {
|
||||||
|
scheduler = common.GetGlobalScheduler()
|
||||||
|
} else {
|
||||||
|
scheduler = common.GetAppScheduler(appName)
|
||||||
|
}
|
||||||
|
|
||||||
fileLock := flock.New(lockFile)
|
fileLock := flock.New(lockFile)
|
||||||
locked, err := fileLock.TryLock()
|
locked, err := fileLock.TryLock()
|
||||||
@@ -108,7 +113,8 @@ func CommandRetire() error {
|
|||||||
return fmt.Errorf("Failed to acquire ps:retire lock")
|
return fmt.Errorf("Failed to acquire ps:retire lock")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := common.PlugnTrigger("scheduler-retire", []string{scheduler}...); err != nil {
|
common.LogInfo1("Retiring old containers and images")
|
||||||
|
if err := common.PlugnTrigger("scheduler-retire", []string{scheduler, appName}...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ cmd-scheduler-docker-local-report-single() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn-scheduler-docker-local-retire-container() {
|
fn-scheduler-docker-local-retire-container() {
|
||||||
declare APP="$1" CID="$2" DEAD_TIME="$3"
|
declare APP="$1" CID="$2"
|
||||||
local STATE
|
local STATE
|
||||||
|
|
||||||
dokku_log_info1_quiet "Attempting to retire $APP container $CID"
|
dokku_log_verbose_quiet "Attempting to retire $APP container $CID"
|
||||||
STATE="$("$DOCKER_BIN" container inspect --format "{{ .State.Status }}" "$CID" 2>/dev/null || true)"
|
STATE="$("$DOCKER_BIN" container inspect --format "{{ .State.Status }}" "$CID" 2>/dev/null || true)"
|
||||||
if [[ -z "$STATE" ]]; then
|
if [[ -z "$STATE" ]]; then
|
||||||
return
|
return
|
||||||
@@ -108,6 +108,7 @@ fn-scheduler-docker-local-retire-container() {
|
|||||||
fn-scheduler-docker-local-retire-containers() {
|
fn-scheduler-docker-local-retire-containers() {
|
||||||
local DEAD_CONTAINER_FILE="${DOKKU_LIB_ROOT}/data/scheduler-docker-local/dead-containers"
|
local DEAD_CONTAINER_FILE="${DOKKU_LIB_ROOT}/data/scheduler-docker-local/dead-containers"
|
||||||
local APP CID CURRENT_TIME DEAD_TIME STATE
|
local APP CID CURRENT_TIME DEAD_TIME STATE
|
||||||
|
declare SCHEDULER="$1" APP="$2"
|
||||||
|
|
||||||
if [[ ! -f "$DEAD_CONTAINER_FILE" ]]; then
|
if [[ ! -f "$DEAD_CONTAINER_FILE" ]]; then
|
||||||
return
|
return
|
||||||
@@ -117,15 +118,19 @@ fn-scheduler-docker-local-retire-containers() {
|
|||||||
while read line; do
|
while read line; do
|
||||||
[[ -z "$line" ]] && continue
|
[[ -z "$line" ]] && continue
|
||||||
CURRENT_TIME="$(date +%s)"
|
CURRENT_TIME="$(date +%s)"
|
||||||
APP="$(echo "$line" | cut -d ' ' -f1)"
|
RETIRE_APP="$(echo "$line" | cut -d ' ' -f1)"
|
||||||
CID="$(echo "$line" | cut -d ' ' -f2)"
|
CID="$(echo "$line" | cut -d ' ' -f2)"
|
||||||
DEAD_TIME="$(echo "$line" | cut -d ' ' -f3)"
|
DEAD_TIME="$(echo "$line" | cut -d ' ' -f3)"
|
||||||
|
|
||||||
|
if [[ -n "$APP" ]] && [[ "$APP" != "$RETIRE_APP" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$CURRENT_TIME" -le "$DEAD_TIME" ]]; then
|
if [[ "$CURRENT_TIME" -le "$DEAD_TIME" ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fn-scheduler-docker-local-retire-container "$APP" "$CID" "$DEAD_TIME"
|
fn-scheduler-docker-local-retire-container "$RETIRE_APP" "$CID"
|
||||||
STATE="$("$DOCKER_BIN" container inspect --format "{{ .State.Status }}" "$CID" 2>/dev/null || true)"
|
STATE="$("$DOCKER_BIN" container inspect --format "{{ .State.Status }}" "$CID" 2>/dev/null || true)"
|
||||||
if [[ -z "$STATE" ]]; then
|
if [[ -z "$STATE" ]]; then
|
||||||
DEAD_CONTAINERS+=("$CID")
|
DEAD_CONTAINERS+=("$CID")
|
||||||
@@ -154,6 +159,7 @@ fn-scheduler-docker-local-retire-containers() {
|
|||||||
fn-scheduler-docker-local-retire-images() {
|
fn-scheduler-docker-local-retire-images() {
|
||||||
local DEAD_IMAGE_FILE="${DOKKU_LIB_ROOT}/data/scheduler-docker-local/dead-images"
|
local DEAD_IMAGE_FILE="${DOKKU_LIB_ROOT}/data/scheduler-docker-local/dead-images"
|
||||||
local APP IMAGE_ID CURRENT_TIME DEAD_TIME STATE RM_OUTPUT
|
local APP IMAGE_ID CURRENT_TIME DEAD_TIME STATE RM_OUTPUT
|
||||||
|
declare SCHEDULER="$1" APP="$2"
|
||||||
|
|
||||||
if [[ ! -f "$DEAD_IMAGE_FILE" ]]; then
|
if [[ ! -f "$DEAD_IMAGE_FILE" ]]; then
|
||||||
return
|
return
|
||||||
@@ -163,10 +169,14 @@ fn-scheduler-docker-local-retire-images() {
|
|||||||
while read line; do
|
while read line; do
|
||||||
[[ -z "$line" ]] && continue
|
[[ -z "$line" ]] && continue
|
||||||
CURRENT_TIME="$(date +%s)"
|
CURRENT_TIME="$(date +%s)"
|
||||||
APP="$(echo "$line" | cut -d ' ' -f1)"
|
RETIRE_APP="$(echo "$line" | cut -d ' ' -f1)"
|
||||||
IMAGE_ID="$(echo "$line" | cut -d ' ' -f2)"
|
IMAGE_ID="$(echo "$line" | cut -d ' ' -f2)"
|
||||||
DEAD_TIME="$(echo "$line" | cut -d ' ' -f3)"
|
DEAD_TIME="$(echo "$line" | cut -d ' ' -f3)"
|
||||||
|
|
||||||
|
if [[ -n "$APP" ]] && [[ "$APP" != "$RETIRE_APP" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$CURRENT_TIME" -le "$DEAD_TIME" ]]; then
|
if [[ "$CURRENT_TIME" -le "$DEAD_TIME" ]]; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
@@ -177,7 +187,7 @@ fn-scheduler-docker-local-retire-images() {
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dokku_log_info1_quiet "Attempting to retire $APP image $IMAGE_ID"
|
dokku_log_verbose_quiet "Attempting to retire $RETIRE_APP image $IMAGE_ID"
|
||||||
if RM_OUTPUT="$("$DOCKER_BIN" image rm "$IMAGE_ID" 2>&1)"; then
|
if RM_OUTPUT="$("$DOCKER_BIN" image rm "$IMAGE_ID" 2>&1)"; then
|
||||||
DEAD_IMAGES+=("$IMAGE_ID")
|
DEAD_IMAGES+=("$IMAGE_ID")
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ source "$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/internal-functions"
|
|||||||
trigger-scheduler-docker-local-scheduler-retire() {
|
trigger-scheduler-docker-local-scheduler-retire() {
|
||||||
declare desc="retires all old containers once they have aged out"
|
declare desc="retires all old containers once they have aged out"
|
||||||
declare trigger="scheduler-retire"
|
declare trigger="scheduler-retire"
|
||||||
|
declare SCHEDULER="$1" APP="$2"
|
||||||
|
|
||||||
fn-scheduler-docker-local-retire-containers
|
fn-scheduler-docker-local-retire-containers "$SCHEDULER" "$APP"
|
||||||
fn-scheduler-docker-local-retire-images
|
fn-scheduler-docker-local-retire-images "$SCHEDULER" "$APP"
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger-scheduler-docker-local-scheduler-retire "$@"
|
trigger-scheduler-docker-local-scheduler-retire "$@"
|
||||||
Reference in new issue
Block a user