feat: implement ps:retire

This commit is contained in:
Jose Diaz-Gonzalez
2020-11-21 20:56:59 -05:00
parent 5fd1772c3a
commit 53a76b1353
5 changed files with 35 additions and 5 deletions

View File

@@ -74,8 +74,13 @@ func GetAppScheduler(appName string) string {
return value
}
b, _ = PlugnTriggerOutput("config-get-global", []string{"DOKKU_SCHEDULER"}...)
value = string(b[:])
return GetGlobalScheduler()
}
// GetGlobalScheduler fetchs the global scheduler
func GetGlobalScheduler() string {
b, _ := PlugnTriggerOutput("config-get-global", []string{"DOKKU_SCHEDULER"}...)
value := string(b[:])
if value != "" {
return value
}

View File

@@ -5,11 +5,14 @@ go 1.14
require (
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27
github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000
github.com/dokku/dokku/plugins/config v0.0.0-00010101000000-000000000000
github.com/dokku/dokku/plugins/docker-options v0.0.0-00010101000000-000000000000
github.com/dokku/dokku/plugins/config v0.0.0-00010101000000-000000000000
github.com/dokku/dokku/plugins/docker-options v0.0.0-00010101000000-000000000000
github.com/gofrs/flock v0.8.0
github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3
)
replace github.com/dokku/dokku/plugins/common => ../common
replace github.com/dokku/dokku/plugins/config => ../config
replace github.com/dokku/dokku/plugins/docker-options => ../docker-options

View File

@@ -3,6 +3,8 @@ github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcju
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27 h1:HHUr4P/aKh4quafGxDT9LDasjGdlGkzLbfmmrlng3kA=
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE=
github.com/dokku/dokku v0.21.4 h1:WG0hyPzNqKqoQXuI7H/N+cWX9B7mAxTW6Yop40BjCQk=
github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY=
github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/joho/godotenv v1.2.0 h1:vGTvz69FzUFp+X4/bAkb0j5BoLC+9bpqTWY8mjhA9pc=
github.com/joho/godotenv v1.2.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=

View File

@@ -3,11 +3,13 @@ package ps
import (
"errors"
"fmt"
"path/filepath"
"strings"
dockeroptions "github.com/dokku/dokku/plugins/docker-options"
"github.com/dokku/dokku/plugins/common"
"github.com/gofrs/flock"
)
// CommandInspect displays a sanitized version of docker inspect for an app
@@ -108,8 +110,25 @@ func CommandRestore(appName string, allApps bool, parallelCount int) error {
}
// CommandRetire ensures old containers are retired
// TODO: implement me
func CommandRetire() error {
lockFile := filepath.Join(common.MustGetEnv("DOKKU_LIB_ROOT"), "data", "ps", "retire")
scheduler := common.GetGlobalScheduler()
fileLock := flock.New(lockFile)
locked, err := fileLock.TryLock()
if err != nil {
return fmt.Errorf("Failed to acquire ps:retire lock: %s", err)
}
defer fileLock.Unlock()
if !locked {
return fmt.Errorf("Failed to acquire ps:retire lock")
}
if err := common.PlugnTrigger("scheduler-retire", []string{scheduler}...); err != nil {
return err
}
return nil
}

View File

@@ -70,6 +70,7 @@ fn-scheduler-docker-local-retire-container() {
declare APP="$1" CID="$2" DEAD_TIME="$3"
local STATE
dokku_log_info1_quiet "Attempting to retire $APP container $CID"
STATE="$("$DOCKER_BIN" container inspect --format "{{ .State.Status }}" "$CID" 2>/dev/null || true)"
if [[ -z "$STATE" ]]; then
return