config: add ability to enable/disable server crash detection

fixes https://github.com/pterodactyl/panel/issues/3617

Co-authored-by: Alex <admin@softwarenoob.com>
This commit is contained in:
Matthew Penner 2021-09-13 15:00:26 -06:00
parent 12b6b64086
commit e79694d6d2
No known key found for this signature in database
GPG Key ID: 030E4AB751DC756F
2 changed files with 20 additions and 13 deletions

View File

@ -48,10 +48,12 @@ var DefaultTLSConfig = &tls.Config{
CurvePreferences: []tls.CurveID{tls.X25519, tls.CurveP256},
}
var mu sync.RWMutex
var _config *Configuration
var _jwtAlgo *jwt.HMACSHA
var _debugViaFlag bool
var (
mu sync.RWMutex
_config *Configuration
_jwtAlgo *jwt.HMACSHA
_debugViaFlag bool
)
// Locker specific to writing the configuration to the disk, this happens
// in areas that might already be locked, so we don't want to crash the process.
@ -181,6 +183,9 @@ type SystemConfiguration struct {
}
type CrashDetection struct {
// CrashDetectionEnabled sets if crash detection is enabled globally for all servers on this node.
CrashDetectionEnabled bool `default:"true" yaml:"enabled"`
// Determines if Wings should detect a server that stops with a normal exit code of
// "0" as being crashed if the process stopped without any Wings interaction. E.g.
// the user did not press the stop button, but the process stopped cleanly.
@ -375,7 +380,7 @@ func WriteToDisk(c *Configuration) error {
if err != nil {
return err
}
if err := ioutil.WriteFile(c.path, b, 0600); err != nil {
if err := ioutil.WriteFile(c.path, b, 0o600); err != nil {
return err
}
return nil
@ -470,7 +475,7 @@ func FromFile(path string) error {
func ConfigureDirectories() error {
root := _config.System.RootDirectory
log.WithField("path", root).Debug("ensuring root data directory exists")
if err := os.MkdirAll(root, 0700); err != nil {
if err := os.MkdirAll(root, 0o700); err != nil {
return err
}
@ -491,17 +496,17 @@ func ConfigureDirectories() error {
}
log.WithField("path", _config.System.Data).Debug("ensuring server data directory exists")
if err := os.MkdirAll(_config.System.Data, 0700); err != nil {
if err := os.MkdirAll(_config.System.Data, 0o700); err != nil {
return err
}
log.WithField("path", _config.System.ArchiveDirectory).Debug("ensuring archive data directory exists")
if err := os.MkdirAll(_config.System.ArchiveDirectory, 0700); err != nil {
if err := os.MkdirAll(_config.System.ArchiveDirectory, 0o700); err != nil {
return err
}
log.WithField("path", _config.System.BackupDirectory).Debug("ensuring backup data directory exists")
if err := os.MkdirAll(_config.System.BackupDirectory, 0700); err != nil {
if err := os.MkdirAll(_config.System.BackupDirectory, 0o700); err != nil {
return err
}

View File

@ -188,7 +188,9 @@ func (s *Server) Sync() error {
// can be called from scoped where the server may not be fully initialized,
// therefore other things like the filesystem and environment may not exist yet.
func (s *Server) SyncWithConfiguration(cfg remote.ServerConfigurationResponse) error {
c := Configuration{}
c := Configuration{
CrashDetectionEnabled: config.Get().System.CrashDetection.CrashDetectionEnabled,
}
if err := json.Unmarshal(cfg.Settings, &c); err != nil {
return errors.WithStackIf(err)
}
@ -196,9 +198,9 @@ func (s *Server) SyncWithConfiguration(cfg remote.ServerConfigurationResponse) e
s.cfg.mu.Lock()
defer s.cfg.mu.Unlock()
// Lock the new configuration. Since we have the defered Unlock above we need
// Lock the new configuration. Since we have the deferred Unlock above we need
// to make sure that the NEW configuration object is already locked since that
// defer is running on the memory address for "s.cfg.mu" which we're explcitly
// defer is running on the memory address for "s.cfg.mu" which we're explicitly
// changing on the next line.
c.mu.Lock()
@ -259,7 +261,7 @@ func (s *Server) EnsureDataDirectoryExists() error {
if _, err := os.Lstat(s.fs.Path()); err != nil {
if os.IsNotExist(err) {
s.Log().Debug("server: creating root directory and setting permissions")
if err := os.MkdirAll(s.fs.Path(), 0700); err != nil {
if err := os.MkdirAll(s.fs.Path(), 0o700); err != nil {
return errors.WithStack(err)
}
if err := s.fs.Chown("/"); err != nil {