From a8ee5463ce9cf1bfba401303df1ebef228c573d4 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 23 Feb 2021 21:23:49 -0800 Subject: [PATCH] Add logic to reset failed server states on Panel when booting --- cmd/root.go | 9 +++++++++ remote/http.go | 1 + remote/servers.go | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index 8132e8d..a0f63f2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -265,6 +265,15 @@ func rootCmdRun(cmd *cobra.Command, _ []string) { } }() + go func() { + log.Info("updating server states on Panel: marking installing/restoring servers as normal") + // Update all of the servers on the Panel to be in a valid state if they're + // currently marked as installing/restoring now that Wings is restarted. + if err := pclient.ResetServersState(cmd.Context()); err != nil { + log.WithField("error", err).Error("failed to reset server states on Panel: some instances may be stuck in an installing/restoring state unexpectedly") + } + }() + sys := config.Get().System // Ensure the archive directory exists. if err := os.MkdirAll(sys.ArchiveDirectory, 0755); err != nil { diff --git a/remote/http.go b/remote/http.go index 24fca52..7b4483a 100644 --- a/remote/http.go +++ b/remote/http.go @@ -21,6 +21,7 @@ type Client interface { GetInstallationScript(ctx context.Context, uuid string) (InstallationScript, error) GetServerConfiguration(ctx context.Context, uuid string) (ServerConfigurationResponse, error) GetServers(context context.Context, perPage int) ([]RawServerData, error) + ResetServersState(ctx context.Context) error SetArchiveStatus(ctx context.Context, uuid string, successful bool) error SetBackupStatus(ctx context.Context, backup string, data BackupRequest) error SendRestorationStatus(ctx context.Context, backup string, successful bool) error diff --git a/remote/servers.go b/remote/servers.go index fa5c3b8..d24ae79 100644 --- a/remote/servers.go +++ b/remote/servers.go @@ -50,6 +50,22 @@ func (c *client) GetServers(ctx context.Context, limit int) ([]RawServerData, er return servers, nil } +// ResetServersState updates the state of all servers on the node that are +// currently marked as "installing" or "restoring from backup" to be marked as +// a normal successful install state. +// +// This handles Wings exiting during either of these processes which will leave +// things in a bad state within the Panel. This API call is executed once Wings +// has fully booted all of the servers. +func (c *client) ResetServersState(ctx context.Context) error { + res, err := c.post(ctx, "/servers/reset", nil) + if err != nil { + return errors.WrapIf(err, "remote/servers: failed to reset server state on Panel") + } + res.Body.Close() + return nil +} + func (c *client) GetServerConfiguration(ctx context.Context, uuid string) (ServerConfigurationResponse, error) { var config ServerConfigurationResponse res, err := c.get(ctx, fmt.Sprintf("/servers/%s", uuid), nil)