fix: implement ps:restore
Also add all the niceties around parallelism that were introduced for the other commands.
This commit is contained in:
1 parent
8ae597ad1d
commit
ab0cc6c444
3 files changed
+67
-3
No files matched your search
@@ -92,6 +92,47 @@ func Restart(appName string) error {
|
|||||||
return common.PlugnTrigger("release-and-deploy", []string{appName}...)
|
return common.PlugnTrigger("release-and-deploy", []string{appName}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore ensures an app that should be running is running on boot
|
||||||
|
func Restore(appName string) error {
|
||||||
|
scheduler := common.GetAppScheduler(appName)
|
||||||
|
if err := common.PlugnTrigger("pre-restore", []string{scheduler, appName}...); err != nil {
|
||||||
|
return fmt.Errorf("Error running pre-restore: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := common.PlugnTrigger("proxy-clear-config", []string{appName}...); err != nil {
|
||||||
|
return fmt.Errorf("Error clearing proxy config: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !common.IsDeployed(appName) {
|
||||||
|
common.LogWarn(fmt.Sprintf("App %s has not been deployed", appName))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_APP_RESTORE"}...)
|
||||||
|
restore := strings.TrimSpace(string(b[:]))
|
||||||
|
if restore == "0" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return Start(appName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RestorePrep() error {
|
||||||
|
apps, err := common.DokkuApps()
|
||||||
|
if err != nil {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, appName := range apps {
|
||||||
|
if err := common.PlugnTrigger("proxy-clear-config", []string{appName}...); err != nil {
|
||||||
|
return fmt.Errorf("Error clearing proxy config: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Start starts the app
|
// Start starts the app
|
||||||
func Start(appName string) error {
|
func Start(appName string) error {
|
||||||
imageTag, _ := common.GetRunningImageTag(appName)
|
imageTag, _ := common.GetRunningImageTag(appName)
|
||||||
|
|||||||
@@ -44,9 +44,11 @@ func main() {
|
|||||||
err = ps.CommandRestart(appName, *allApps, *parallelCount)
|
err = ps.CommandRestart(appName, *allApps, *parallelCount)
|
||||||
case "restore":
|
case "restore":
|
||||||
args := flag.NewFlagSet("ps:restore", flag.ExitOnError)
|
args := flag.NewFlagSet("ps:restore", flag.ExitOnError)
|
||||||
|
allApps := args.Bool("all", false, "--all: restore all apps")
|
||||||
|
parallelCount := args.Int("parallel", ps.RunInSerial, "--parallel: number of apps to restore in parallel, -1 to match cpu count")
|
||||||
args.Parse(os.Args[2:])
|
args.Parse(os.Args[2:])
|
||||||
appName := args.Arg(0)
|
appName := args.Arg(0)
|
||||||
err = ps.CommandRestore(appName)
|
err = ps.CommandRestore(appName, *allApps, *parallelCount)
|
||||||
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:])
|
||||||
|
|||||||
@@ -83,8 +83,29 @@ func CommandRestart(appName string, allApps bool, parallelCount int) error {
|
|||||||
|
|
||||||
// CommandRestore starts previously running apps e.g. after reboot
|
// CommandRestore starts previously running apps e.g. after reboot
|
||||||
// TODO: implement me
|
// TODO: implement me
|
||||||
func CommandRestore(appName string) error {
|
func CommandRestore(appName string, allApps bool, parallelCount int) error {
|
||||||
return nil
|
if allApps {
|
||||||
|
if err := RestorePrep(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return common.RunCommandAgainstAllApps(Restore, "restore", parallelCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
if appName == "" {
|
||||||
|
common.LogWarn("Restore specified without app, assuming --all")
|
||||||
|
|
||||||
|
if err := RestorePrep(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return common.RunCommandAgainstAllApps(Restore, "restore", parallelCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return Restore(appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandRetire ensures old containers are retired
|
// CommandRetire ensures old containers are retired
|
||||||
|
|||||||
Reference in new issue
Block a user