[config] improve logging and default command

This commit is contained in:
Alex Quick
2017-05-04 22:41:32 -04:00
parent 8b90d4ebf9
commit 08aa2b9fa4
5 changed files with 77 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ import (
"strings"
common "github.com/dokku/dokku/plugins/common"
config "github.com/dokku/dokku/plugins/config"
"github.com/dokku/dokku/plugins/config/src/configenv"
)
@@ -36,8 +37,8 @@ func main() {
common.LogFail(err.Error())
}
var changed = false
entries := args.Args()[nextArg:]
updated := make(map[string]string)
for _, e := range entries {
//log
parts := strings.SplitN(e, "=", 2)
@@ -53,17 +54,19 @@ func main() {
value = string(decoded)
}
env.Set(key, value)
changed = true
updated[key] = value
}
if changed {
//log
if len(updated) != 0 {
common.LogInfo1("Setting config vars")
fmt.Println(config.PrettyPrintLogEntries(" ", updated))
env.Write()
args := append([]string{appName, "set"}, entries...)
common.PlugnTrigger("post-config-update", args...)
}
if shouldRestart && env.GetBoolDefault("DOKKU_APP_RESTORE", true) {
common.LogInfo1(fmt.Sprintf("Restarting app %s", appName))
cmd := common.NewTokenizedShellCmd("dokku", "ps:restart", appName)
cmd.Execute()
}

View File

@@ -4,6 +4,8 @@ import (
"flag"
"os"
"fmt"
common "github.com/dokku/dokku/plugins/common"
"github.com/dokku/dokku/plugins/config/src/configenv"
)
@@ -35,19 +37,19 @@ func main() {
var changed = false
keys := args.Args()[nextArg:]
for _, k := range keys {
//log
common.LogInfo1(fmt.Sprintf("Unsetting %s", k))
env.Unset(k)
changed = true
}
if changed {
//log
env.Write()
args := append([]string{appName, "unset"}, keys...)
common.PlugnTrigger("post-config-update", args...)
}
if shouldRestart && env.GetBoolDefault("DOKKU_APP_RESTORE", true) {
common.LogInfo1(fmt.Sprintf("Restarting app %s", appName))
cmd := common.NewTokenizedShellCmd("dokku", "ps:restart", appName)
cmd.Execute()
}