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.
This commit is contained in:
Matthew Penner 2021-10-05 18:42:47 -06:00
parent 6f9783f164
commit 7899a7abdf
No known key found for this signature in database
GPG Key ID: BAB67850901908A8

View File

@ -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")