Documentation ¶
Index ¶
- Constants
- Variables
- func IsServerDoesNotExistError(err error) bool
- func IsTooFrequentCrashError(err error) bool
- type APIResponse
- type Configuration
- type ConfigurationMeta
- type ConsoleThrottle
- type CrashHandler
- type InstallationProcess
- func (ip *InstallationProcess) AfterExecute(containerId string) error
- func (ip *InstallationProcess) BeforeExecute() error
- func (ip *InstallationProcess) Execute() (string, error)
- func (ip *InstallationProcess) GetLogPath() string
- func (ip *InstallationProcess) RemoveContainer() error
- func (ip *InstallationProcess) Run() error
- func (ip *InstallationProcess) StreamOutput(ctx context.Context, id string) error
- type Manager
- func (m *Manager) Add(s *Server)
- func (m *Manager) All() []*Server
- func (m *Manager) Client() remote.Client
- func (m *Manager) Filter(filter func(match *Server) bool) []*Server
- func (m *Manager) Find(filter func(match *Server) bool) *Server
- func (m *Manager) Get(uuid string) (*Server, bool)
- func (m *Manager) InitServer(data remote.ServerConfigurationResponse) (*Server, error)
- func (m *Manager) Keys() []string
- func (m *Manager) Len() int
- func (m *Manager) PersistStates() error
- func (m *Manager) Put(s []*Server)
- func (m *Manager) ReadStates() (map[string]string, error)
- func (m *Manager) Remove(filter func(match *Server) bool)
- type Mount
- type PowerAction
- type RequestActivity
- type ResourceUsage
- type RocketConfiguration
- type Server
- func (s *Server) CleanupForDestroy()
- func (s *Server) Config() *Configuration
- func (s *Server) Context() context.Context
- func (s *Server) CreateEnvironment() error
- func (s *Server) CtxCancel()
- func (s *Server) DestroyAllSinks()
- func (s *Server) DiskSpace() int64
- func (s *Server) Events() *events.Bus
- func (s *Server) ExecutingPowerAction() bool
- func (s *Server) Filesystem() *filesystem.Filesystem
- func (s *Server) GetEnvironmentVariables() []string
- func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error
- func (s *Server) ID() string
- func (s *Server) Id() string
- func (s *Server) Install() error
- func (s *Server) IsInstalling() bool
- func (s *Server) IsRestoring() bool
- func (s *Server) IsRunning() bool
- func (s *Server) IsSuspended() bool
- func (s *Server) IsTransferring() bool
- func (s *Server) Log() *log.Entry
- func (s *Server) MemoryLimit() int64
- func (s *Server) Mounts() []environment.Mount
- func (s *Server) NewRequestActivity(user string, ip string) RequestActivity
- func (s *Server) OnStateChange()
- func (s *Server) Proc() *ResourceUsage
- func (s *Server) ProcessConfiguration() *remote.ProcessConfiguration
- func (s *Server) PublishConsoleOutputFromDaemon(data string)
- func (s *Server) ReadLogfile(len int) ([]string, error)
- func (s *Server) Reinstall(delete bool) error
- func (s *Server) RestoreBackup(b snapshot.BackupInterface, reader io.ReadCloser) (err error)
- func (s *Server) SaveActivity(a RequestActivity, event models.Event, metadata models.ActivityMeta)
- func (s *Server) SetRestoring(state bool)
- func (s *Server) SetTransferring(state bool)
- func (s *Server) Sink(name system.SinkName) *system.SinkPool
- func (s *Server) Snapshot(b snapshot.BackupInterface) error
- func (s *Server) StartEventListeners()
- func (s *Server) Sync() error
- func (s *Server) SyncInstallState(successful, reinstall bool) error
- func (s *Server) SyncWithConfiguration(cfg remote.ServerConfigurationResponse) error
- func (s *Server) SyncWithEnvironment()
- func (s *Server) Throttler() *ConsoleThrottle
- func (s *Server) ToAPIResponse() APIResponse
- func (s *Server) UpdateConfigurationFiles()
- func (s *Server) Websockets() *WebsocketBag
- type WebsocketBag
Constants ¶
const ( ActivityConsoleCommand = models.Event("server:console.command") ActivitySftpWrite = models.Event("server:sftp.write") ActivitySftpCreate = models.Event("server:sftp.create") ActivitySftpCreateDirectory = models.Event("server:sftp.create-directory") ActivitySftpRename = models.Event("server:sftp.rename") ActivitySftpDelete = models.Event("server:sftp.delete") ActivityFileUploaded = models.Event("server:file.uploaded") )
const ( DaemonMessageEvent = "daemon message" InstallOutputEvent = "install output" InstallStartedEvent = "install started" InstallCompletedEvent = "install completed" ConsoleOutputEvent = "console output" StatusEvent = "status" StatsEvent = "stats" JsonEvent = "json" BackupRestoreCompletedEvent = "backup restore completed" BackupCompletedEvent = "backup completed" TransferLogsEvent = "transfer logs" TransferStatusEvent = "transfer status" DeletedEvent = "deleted" )
Defines all the possible output events for a server.
const ( PowerActionStart = "start" PowerActionStop = "stop" PowerActionRestart = "restart" PowerActionTerminate = "kill" )
The power actions that can be performed for a given server. This taps into the given server environment and performs them in a way that prevents a race condition from occurring. For example, sending two "start" actions back to back will not process the second action until the first action has been completed.
This utilizes a workerpool with a limit of one worker so that all the actions execute in a sync manner.
const ActivityPowerPrefix = "server:power."
Variables ¶
var ( ErrIsRunning = errors.New("server is running") ErrSuspended = errors.New("server is currently in a suspended state") ErrServerIsInstalling = errors.New("server is currently installing") ErrServerIsTransferring = errors.New("server is currently being transferred") ErrServerIsRestoring = errors.New("server is currently being restored") )
Functions ¶
func IsTooFrequentCrashError ¶
Types ¶
type APIResponse ¶
type APIResponse struct { State string `json:"state"` IsSuspended bool `json:"is_suspended"` Utilization ResourceUsage `json:"utilization"` Configuration Configuration `json:"configuration"` Services []v1.Service `json:"services"` }
APIResponse is a type returned when requesting details about a single server instance on Kuber. This includes the information needed by the Panel in order to show resource utilization and the current state on this system.
type Configuration ¶
type Configuration struct { // 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"` Meta ConfigurationMeta `json:"meta"` // 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"` // 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. SkipRocketScripts bool `json:"skip_rocket_scripts"` // An array of environment variables that should be passed along to the running // server process. EnvVars environment.Variables `json:"environment"` // Labels is a map of container labels that should be applied to the running server process. Labels map[string]string `json:"labels"` Ports environment.Ports `json:"ports"` Allocations environment.Allocations `json:"allocations"` Build environment.Limits `json:"build"` CrashDetectionEnabled bool `json:"crash_detection_enabled"` Mounts []Mount `json:"mounts"` Rocket RocketConfiguration `json:"rocket,omitempty"` NodeSelectors map[string]string `json:"node_selectors"` Container struct { // Defines the Docker image that will be used for this server Image string `json:"image,omitempty"` } `json:"container,omitempty"` // contains filtered or unexported fields }
func (*Configuration) GetUuid ¶
func (c *Configuration) GetUuid() string
func (*Configuration) SetSuspended ¶
func (c *Configuration) SetSuspended(s bool)
type ConfigurationMeta ¶
type ConsoleThrottle ¶
type ConsoleThrottle struct {
// contains filtered or unexported fields
}
func (*ConsoleThrottle) Allow ¶
func (ct *ConsoleThrottle) Allow() bool
Allow checks if the console is allowed to process more output data, or if too much has already been sent over the line. If there is too much output the strike callback function is triggered, but only if it has not already been triggered at this point in the process.
If output is allowed, the lock on the throttler is released and the next time it is triggered the strike function will be re-executed.
func (*ConsoleThrottle) Reset ¶
func (ct *ConsoleThrottle) Reset()
Reset resets the console throttler internal rate limiter and overage counter.
type CrashHandler ¶
type CrashHandler struct {
// contains filtered or unexported fields
}
func (*CrashHandler) LastCrashTime ¶
func (cd *CrashHandler) LastCrashTime() time.Time
Returns the time of the last crash for this server instance.
func (*CrashHandler) SetLastCrash ¶
func (cd *CrashHandler) SetLastCrash(t time.Time)
Sets the last crash time for a server.
type InstallationProcess ¶
type InstallationProcess struct { Server *Server Script *remote.InstallationScript // contains filtered or unexported fields }
func NewInstallationProcess ¶
func NewInstallationProcess(s *Server, script *remote.InstallationScript) (*InstallationProcess, error)
NewInstallationProcess returns a new installation process struct that will be used to create containers and otherwise perform installation commands for a server.
func (*InstallationProcess) AfterExecute ¶
func (ip *InstallationProcess) AfterExecute(containerId string) error
AfterExecute cleans up after the execution of the installation process. This grabs the logs from the process to store in the server configuration directory, and then destroys the associated installation container.
func (*InstallationProcess) BeforeExecute ¶
func (ip *InstallationProcess) BeforeExecute() error
BeforeExecute runs before the container is executed. This pulls down the required docker container image as well as writes the installation script to the disk. This process is executed in an async manner, if either one fails the error is returned.
func (*InstallationProcess) Execute ¶
func (ip *InstallationProcess) Execute() (string, error)
Execute executes the installation process inside a specially created Kubernetes pod container.
func (*InstallationProcess) GetLogPath ¶
func (ip *InstallationProcess) GetLogPath() string
GetLogPath returns the log path for the installation process.
func (*InstallationProcess) RemoveContainer ¶
func (ip *InstallationProcess) RemoveContainer() error
RemoveContainer removes the installation container for the server.
func (*InstallationProcess) Run ¶
func (ip *InstallationProcess) Run() error
Run runs the installation process, this is done as in a background thread. This will configure the required environment, and then spin up the installation container. Once the container finishes installing the results are stored in an installation log in the server's configuration directory.
func (*InstallationProcess) StreamOutput ¶
func (ip *InstallationProcess) StreamOutput(ctx context.Context, id string) error
StreamOutput streams the output of the installation process to a log file in the server configuration directory, as well as to a websocket listener so that the process can be viewed in the panel by administrators.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewEmptyManager ¶
NewEmptyManager returns a new empty manager collection without actually loading any of the servers from the disk. This allows the caller to set their own servers into the collection as needed.
func NewManager ¶
NewManager returns a new server manager instance. This will boot up all the servers that are currently present on the filesystem and set them into the manager.
func (*Manager) Client ¶
Client returns the HTTP client interface that allows interaction with the Panel API.
func (*Manager) Find ¶
Find returns a single element from the collection matching the filter. If nothing is found a nil result is returned.
func (*Manager) Get ¶
Get returns a single server instance and a boolean value indicating if it was found in the global collection or not.
func (*Manager) InitServer ¶
func (m *Manager) InitServer(data remote.ServerConfigurationResponse) (*Server, error)
InitServer initializes a server using a data byte array. This will be marshaled into the given struct using a YAML marshaler. This will also configure the given environment for a server.
func (*Manager) PersistStates ¶
PersistStates writes the current environment states to the disk for each server. This is generally called at a specific interval defined in the root runner command to avoid hammering disk I/O when tons of server switch states at once. It is fine if this file falls slightly out of sync, it is just here to make recovering from an unexpected system reboot a little easier.
func (*Manager) Put ¶
Put replaces all the current values in the collection with the value that is passed through.
func (*Manager) ReadStates ¶
ReadStates returns the state of the servers.
type Mount ¶
type Mount environment.Mount
To avoid confusion when working with mounts, assume that a server.Mount has not been properly cleaned up and had the paths set. An environment.Mount should only be returned with valid paths that have been checked.
type PowerAction ¶
type PowerAction string
func (PowerAction) IsStart ¶
func (pa PowerAction) IsStart() bool
func (PowerAction) IsValid ¶
func (pa PowerAction) IsValid() bool
IsValid checks if the power action being received is valid.
type RequestActivity ¶
type RequestActivity struct {
// contains filtered or unexported fields
}
RequestActivity is a wrapper around a LoggedEvent that is able to track additional request specific metadata including the specific user and IP address associated with all subsequent events. The internal logged event structure can be extracted by calling RequestEvent.Event().
func (RequestActivity) Event ¶
func (ra RequestActivity) Event(event models.Event, metadata models.ActivityMeta) *models.Activity
Event returns the underlying logged event from the RequestEvent instance and sets the specific event and metadata on it.
func (RequestActivity) SetUser ¶
func (ra RequestActivity) SetUser(u string) RequestActivity
SetUser clones the RequestActivity struct and sets a new user value on the copy before returning it.
type ResourceUsage ¶
type ResourceUsage struct { // Embed the current environment stats into this server specific resource usage struct. environment.Stats // The current server status. State *system.AtomicString `json:"state"` // The current disk space being used by the server. This value is not guaranteed to be accurate // at all times. It is "manually" set whenever server.Proc() is called. This is kind of just a // hacky solution for now to avoid passing events all over the place. Disk int64 `json:"disk_bytes"` // contains filtered or unexported fields }
ResourceUsage defines the current resource usage for a given server instance. If a server is offline you should obviously expect memory and CPU usage to be 0. However, disk will always be returned since that is not dependent on the server being running to collect that data.
func (*ResourceUsage) Reset ¶
func (ru *ResourceUsage) Reset()
Reset resets the usages values to zero, used when a server is stopped to ensure we don't hold onto any values incorrectly.
func (*ResourceUsage) UpdateStats ¶
func (ru *ResourceUsage) UpdateStats(stats environment.Stats)
UpdateStats updates the current stats for the server's resource usage.
type RocketConfiguration ¶
type RocketConfiguration struct { // The internal UUID of the Rocket on the Panel. ID string `json:"id"` // 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 Rocket level. FileDenylist []string `json:"file_denylist"` }
type Server ¶
type Server struct { // Internal mutex used to block actions that need to occur sequentially, such as // writing the configuration to the disk. sync.RWMutex Environment environment.ProcessEnvironment `json:"-"` // contains filtered or unexported fields }
Server is the high level definition for a server instance being controlled by Kuber.
func New ¶
New returns a new server instance with a context and all of the default values set on the struct.
func (*Server) CleanupForDestroy ¶
func (s *Server) CleanupForDestroy()
CleanupForDestroy stops all running background tasks for this server that are using the context on the server struct. This will cancel any running install processes for the server as well.
func (*Server) Config ¶
func (s *Server) Config() *Configuration
func (*Server) Context ¶
Returns a context instance for the server. This should be used to allow background tasks to be canceled if the server is removed. It will only be canceled when the application is stopped or if the server gets deleted.
func (*Server) CreateEnvironment ¶
Initializes a server instance. This will run through and ensure that the environment for the server is setup, and that all of the necessary files are created.
func (*Server) CtxCancel ¶
func (s *Server) CtxCancel()
Cancels the context assigned to this server instance. Assuming background tasks are using this server's context for things, all of the background tasks will be stopped as a result.
func (*Server) DestroyAllSinks ¶
func (s *Server) DestroyAllSinks()
DestroyAllSinks iterates over all of the sinks configured for the server and destroys their instances. Note that this will cause a panic if you attempt to call Server.Sink() again after. This function is only used when a server is being deleted from the system.
func (*Server) DiskSpace ¶
DiskSpace returns the amount of disk space available to a server in bytes.
func (*Server) ExecutingPowerAction ¶
ExecutingPowerAction checks if there is currently a power action being processed for the server.
func (*Server) Filesystem ¶
func (s *Server) Filesystem() *filesystem.Filesystem
Filesystem returns an instance of the filesystem for this server.
func (*Server) GetEnvironmentVariables ¶
Returns all of the environment variables that should be assigned to a running server instance.
func (*Server) HandlePowerAction ¶
func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error
HandlePowerAction is a helper function that can receive a power action and then process the actions that need to occur for it. This guards against someone calling Start() twice at the same time, or trying to restart while another restart process is currently running.
However, the code design for the daemon does depend on the user correctly calling this function rather than making direct calls to the start/stop/restart functions on the environment struct.
func (*Server) Id ¶
Id returns the UUID for the server instance. This function is deprecated in favor of Server.ID().
Deprecated
func (*Server) Install ¶
Install executes the installation stack for a server process. Bubbles any errors up to the calling function which should handle contacting the panel to notify it of the server state.
Pass true as the first argument in order to execute a server sync before the process to ensure the latest information is used.
func (*Server) IsInstalling ¶
IsInstalling returns if the server is actively running the installation process by checking the status of the installer lock.
func (*Server) IsRestoring ¶
func (*Server) IsRunning ¶
IsRunning determines if the server state is running or not. This is different from the environment state, it is simply the tracked state from this daemon instance, and not the response from Kubernetes.
func (*Server) IsSuspended ¶
Checks if the server is marked as being suspended or not on the system.
func (*Server) IsTransferring ¶
func (*Server) MemoryLimit ¶
func (*Server) Mounts ¶
func (s *Server) Mounts() []environment.Mount
Returns the default container mounts for the server instance. This includes the data directory for the server. Previously this would also mount in host timezone files, however we've moved from that approach to just setting `TZ=Timezone` environment values in containers which should work in most scenarios.
func (*Server) NewRequestActivity ¶
func (s *Server) NewRequestActivity(user string, ip string) RequestActivity
func (*Server) OnStateChange ¶
func (s *Server) OnStateChange()
OnStateChange sets the state of the server internally. This function handles crash detection as well as reporting to event listeners for the server.
func (*Server) Proc ¶
func (s *Server) Proc() *ResourceUsage
Proc returns the current resource usage stats for the server instance. This returns a copy of the tracked resources, so making any changes to the response will not have the desired outcome for you most likely.
func (*Server) ProcessConfiguration ¶
func (s *Server) ProcessConfiguration() *remote.ProcessConfiguration
func (*Server) PublishConsoleOutputFromDaemon ¶
PublishConsoleOutputFromDaemon sends output to the server console formatted to appear correctly as being sent from Kuber.
func (*Server) ReadLogfile ¶
Reads the log file for a server up to a specified number of bytes.
func (*Server) Reinstall ¶
Reinstall reinstalls a server's software by utilizing the installation script for the server rocket. This does not touch any existing files for the server, other than what the script modifies.
func (*Server) RestoreBackup ¶
func (s *Server) RestoreBackup(b snapshot.BackupInterface, reader io.ReadCloser) (err error)
RestoreBackup calls the Restore function on the provided snapshot. Once this restoration is completed an event is emitted to the websocket to notify the Panel that is has been completed.
In addition to the websocket event an API call is triggered to notify the Panel of the new state.
func (*Server) SaveActivity ¶
func (s *Server) SaveActivity(a RequestActivity, event models.Event, metadata models.ActivityMeta)
SaveActivity saves an activity entry to the database in a background routine. If an error is encountered it is logged but not returned to the caller.
func (*Server) SetRestoring ¶
func (*Server) SetTransferring ¶
func (*Server) Sink ¶
Sink returns the instantiated and named sink for a server. If the sink has not been configured yet this function will cause a panic condition.
func (*Server) Snapshot ¶
func (s *Server) Snapshot(b snapshot.BackupInterface) error
Snapshot performs a server snapshot and then emits the event over the server websocket. We let the actual snapshot system handle notifying the panel of the status, but that won't emit a websocket event.
func (*Server) StartEventListeners ¶
func (s *Server) StartEventListeners()
StartEventListeners adds all the internal event listeners we want to use for a server. These listeners can only be removed by deleting the server as they should last for the duration of the process' lifetime.
func (*Server) Sync ¶
Sync syncs the state of the server on the Panel with Kuber. This ensures that we're always using the state of the server from the Panel and allows us to not require successful API calls to Kuber to do things.
This also means mass actions can be performed against servers on the Panel and they will automatically sync with Kuber when the server is started.
func (*Server) SyncInstallState ¶
SyncInstallState makes an HTTP request to the Panel instance notifying it that the server has completed the installation process, and what the state of the server is.
func (*Server) SyncWithConfiguration ¶
func (s *Server) SyncWithConfiguration(cfg remote.ServerConfigurationResponse) error
SyncWithConfiguration accepts a configuration object for a server and will sync all of the values with the existing server state. This only replaces the existing configuration and process configuration for the server. The underlying environment will not be affected. This is because this function 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 (*Server) SyncWithEnvironment ¶
func (s *Server) SyncWithEnvironment()
SyncWithEnvironment updates the environment for the server to match any of the changed data. This pushes new settings and environment variables to the environment. In addition, the in-situ update method is called on the environment which will allow environments that make use of it (such as Docker) to immediately apply some settings without having to wait on a server to restart.
This functionality allows a server's resources limits to be modified on the fly and have them apply right away allowing for dynamic resource allocation and responses to abusive server processes.
func (*Server) Throttler ¶
func (s *Server) Throttler() *ConsoleThrottle
Throttler returns the throttler instance for the server or creates a new one.
func (*Server) ToAPIResponse ¶
func (s *Server) ToAPIResponse() APIResponse
ToAPIResponse returns the server struct as an API object that can be consumed by callers.
func (*Server) UpdateConfigurationFiles ¶
func (s *Server) UpdateConfigurationFiles()
UpdateConfigurationFiles updates all of the defined configuration files for a server automatically to ensure that they always use the specified values.
func (*Server) Websockets ¶
func (s *Server) Websockets() *WebsocketBag
Websockets returns the websocket bag which contains all the currently open websocket connections for the server instance.
type WebsocketBag ¶
type WebsocketBag struct {
// contains filtered or unexported fields
}
func (*WebsocketBag) CancelAll ¶
func (w *WebsocketBag) CancelAll()
CancelAll cancels all the stored cancel functions which has the effect of disconnecting every listening websocket for the server.
func (*WebsocketBag) Push ¶
func (w *WebsocketBag) Push(u uuid.UUID, cancel *context.CancelFunc)
Push adds a new websocket connection to the end of the stack.
func (*WebsocketBag) Remove ¶
func (w *WebsocketBag) Remove(u uuid.UUID)
Remove removes a connection from the stack.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package transfer handles all logic related to transferring servers between two nodes.
|
Package transfer handles all logic related to transferring servers between two nodes. |