fix: implement ps:restore

Also add all the niceties around parallelism that were introduced for the other commands.
This commit is contained in:
Jose Diaz-Gonzalez
2020-11-21 20:37:54 -05:00
parent 8ae597ad1d
commit ab0cc6c444
3 changed files with 67 additions and 3 deletions

View File

@@ -92,6 +92,47 @@ func Restart(appName string) error {
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
func Start(appName string) error {
imageTag, _ := common.GetRunningImageTag(appName)

View File

@@ -44,9 +44,11 @@ func main() {
err = ps.CommandRestart(appName, *allApps, *parallelCount)
case "restore":
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:])
appName := args.Arg(0)
err = ps.CommandRestore(appName)
err = ps.CommandRestore(appName, *allApps, *parallelCount)
case "retire":
args := flag.NewFlagSet("ps:retire", flag.ExitOnError)
args.Parse(os.Args[2:])

View File

@@ -83,8 +83,29 @@ func CommandRestart(appName string, allApps bool, parallelCount int) error {
// CommandRestore starts previously running apps e.g. after reboot
// TODO: implement me
func CommandRestore(appName string) error {
return nil
func CommandRestore(appName string, allApps bool, parallelCount int) error {
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