2020-07-19 23:27:55 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
2021-01-10 01:22:39 +00:00
|
|
|
|
|
|
|
"github.com/pterodactyl/wings/environment"
|
2020-07-19 23:27:55 +00:00
|
|
|
)
|
|
|
|
|
2021-01-11 00:33:39 +00:00
|
|
|
type EggConfiguration struct {
|
|
|
|
// The internal UUID of the Egg on the Panel.
|
2021-04-03 18:08:26 +00:00
|
|
|
ID string `json:"id"`
|
2021-01-11 00:33:39 +00:00
|
|
|
|
|
|
|
// Maintains a list of files that are blacklisted for opening/editing/downloading
|
|
|
|
// or basically any type of access on the server by any user. This is NOT the same
|
|
|
|
// as a per-user denylist, this is defined at the Egg level.
|
|
|
|
FileDenylist []string `json:"file_denylist"`
|
|
|
|
}
|
|
|
|
|
2022-07-24 21:16:45 +00:00
|
|
|
type ConfigurationMeta struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
}
|
|
|
|
|
2020-07-19 23:27:55 +00:00
|
|
|
type Configuration struct {
|
|
|
|
mu sync.RWMutex
|
|
|
|
|
|
|
|
// The unique identifier for the server that should be used when referencing
|
|
|
|
// it against the Panel API (and internally). This will be used when naming
|
|
|
|
// docker containers as well as in log output.
|
|
|
|
Uuid string `json:"uuid"`
|
|
|
|
|
2022-07-24 21:16:45 +00:00
|
|
|
Meta ConfigurationMeta `json:"meta"`
|
|
|
|
|
2020-07-19 23:27:55 +00:00
|
|
|
// Whether or not the server is in a suspended state. Suspended servers cannot
|
|
|
|
// be started or modified except in certain scenarios by an admin user.
|
|
|
|
Suspended bool `json:"suspended"`
|
|
|
|
|
|
|
|
// The command that should be used when booting up the server instance.
|
|
|
|
Invocation string `json:"invocation"`
|
|
|
|
|
2020-08-30 16:41:14 +00:00
|
|
|
// By default this is false, however if selected within the Panel while installing or re-installing a
|
|
|
|
// server, specific installation scripts will be skipped for the server process.
|
2021-07-04 22:08:05 +00:00
|
|
|
SkipEggScripts bool `json:"skip_egg_scripts"`
|
|
|
|
|
2020-07-19 23:27:55 +00:00
|
|
|
// An array of environment variables that should be passed along to the running
|
|
|
|
// server process.
|
2020-08-11 04:38:42 +00:00
|
|
|
EnvVars environment.Variables `json:"environment"`
|
2020-07-19 23:27:55 +00:00
|
|
|
|
2020-08-11 04:38:42 +00:00
|
|
|
Allocations environment.Allocations `json:"allocations"`
|
|
|
|
Build environment.Limits `json:"build"`
|
2021-07-04 22:08:05 +00:00
|
|
|
CrashDetectionEnabled bool `json:"crash_detection_enabled"`
|
2020-08-11 04:38:42 +00:00
|
|
|
Mounts []Mount `json:"mounts"`
|
2021-01-11 00:33:39 +00:00
|
|
|
Egg EggConfiguration `json:"egg,omitempty"`
|
2020-07-19 23:27:55 +00:00
|
|
|
|
|
|
|
Container struct {
|
|
|
|
// Defines the Docker image that will be used for this server
|
|
|
|
Image string `json:"image,omitempty"`
|
|
|
|
} `json:"container,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) Config() *Configuration {
|
|
|
|
s.cfg.mu.RLock()
|
|
|
|
defer s.cfg.mu.RUnlock()
|
|
|
|
return &s.cfg
|
|
|
|
}
|
|
|
|
|
2021-07-04 22:08:05 +00:00
|
|
|
// DiskSpace returns the amount of disk space available to a server in bytes.
|
2020-08-28 04:08:33 +00:00
|
|
|
func (s *Server) DiskSpace() int64 {
|
|
|
|
s.cfg.mu.RLock()
|
|
|
|
defer s.cfg.mu.RUnlock()
|
2020-09-26 03:31:33 +00:00
|
|
|
return s.cfg.Build.DiskSpace * 1024.0 * 1024.0
|
2020-08-28 04:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) MemoryLimit() int64 {
|
|
|
|
s.cfg.mu.RLock()
|
|
|
|
defer s.cfg.mu.RUnlock()
|
|
|
|
return s.cfg.Build.MemoryLimit
|
|
|
|
}
|
|
|
|
|
2020-07-20 00:46:39 +00:00
|
|
|
func (c *Configuration) GetUuid() string {
|
|
|
|
c.mu.RLock()
|
|
|
|
defer c.mu.RUnlock()
|
|
|
|
return c.Uuid
|
|
|
|
}
|
|
|
|
|
2020-07-19 23:27:55 +00:00
|
|
|
func (c *Configuration) SetSuspended(s bool) {
|
|
|
|
c.mu.Lock()
|
2021-07-04 22:08:05 +00:00
|
|
|
defer c.mu.Unlock()
|
2020-07-19 23:27:55 +00:00
|
|
|
c.Suspended = s
|
|
|
|
}
|