From 7899a7abdf063e0d0f2381ba26c9451e288e635a Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Tue, 5 Oct 2021 18:42:47 -0600 Subject: [PATCH] re-sync server config if container is already running If wings is restarted while a container is already running, the server will be missing it's configuration, specifically it's stop configuration. This will cause the stop power action to terminate the server due to no stop command being set. --- cmd/root.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 8658088..3be824e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -214,7 +214,7 @@ func rootCmdRun(cmd *cobra.Command, _ []string) { // // @see https://github.com/pterodactyl/panel/issues/2475 // @see https://github.com/pterodactyl/panel/issues/3358 - ctx, cancel := context.WithTimeout(cmd.Context(), time.Second * 30) + ctx, cancel := context.WithTimeout(cmd.Context(), time.Second*30) defer cancel() r, err := s.Environment.IsRunning(ctx) @@ -255,6 +255,13 @@ func rootCmdRun(cmd *cobra.Command, _ []string) { // state being tracked. s.Environment.SetState(environment.ProcessOfflineState) } + + if state := s.Environment.State(); state == environment.ProcessStartingState || state == environment.ProcessRunningState { + s.Log().Debug("re-syncing server configuration for already running server") + if err := s.Sync(); err != nil { + s.Log().WithError(err).Error("failed to re-sync server configuration") + } + } }) } @@ -287,12 +294,12 @@ func rootCmdRun(cmd *cobra.Command, _ []string) { sys := config.Get().System // Ensure the archive directory exists. - if err := os.MkdirAll(sys.ArchiveDirectory, 0755); err != nil { + if err := os.MkdirAll(sys.ArchiveDirectory, 0o755); err != nil { log.WithField("error", err).Error("failed to create archive directory") } // Ensure the backup directory exists. - if err := os.MkdirAll(sys.BackupDirectory, 0755); err != nil { + if err := os.MkdirAll(sys.BackupDirectory, 0o755); err != nil { log.WithField("error", err).Error("failed to create backup directory") } @@ -385,7 +392,7 @@ func initConfig() { // in the code without having to pass around a logger instance. func initLogging() { dir := config.Get().System.LogDirectory - if err := os.MkdirAll(path.Join(dir, "/install"), 0700); err != nil { + if err := os.MkdirAll(path.Join(dir, "/install"), 0o700); err != nil { log2.Fatalf("cmd/root: failed to create install directory path: %s", err) } p := filepath.Join(dir, "/wings.log")