2020-08-11 04:38:42 +00:00
|
|
|
package environment
|
2019-03-25 00:27:14 +00:00
|
|
|
|
|
|
|
import (
|
2020-08-11 04:38:42 +00:00
|
|
|
"github.com/pterodactyl/wings/events"
|
2019-03-25 01:00:21 +00:00
|
|
|
"os"
|
2019-03-25 00:27:14 +00:00
|
|
|
)
|
|
|
|
|
2020-08-11 04:38:42 +00:00
|
|
|
const (
|
2020-09-13 04:37:48 +00:00
|
|
|
ConsoleOutputEvent = "console output"
|
|
|
|
StateChangeEvent = "state change"
|
|
|
|
ResourceEvent = "resources"
|
|
|
|
DockerImagePullStarted = "docker image pull started"
|
|
|
|
DockerImagePullStatus = "docker image pull status"
|
|
|
|
DockerImagePullCompleted = "docker image pull completed"
|
2020-08-11 04:38:42 +00:00
|
|
|
)
|
|
|
|
|
2020-08-20 01:58:48 +00:00
|
|
|
const (
|
|
|
|
ProcessOfflineState = "offline"
|
|
|
|
ProcessStartingState = "starting"
|
|
|
|
ProcessRunningState = "running"
|
|
|
|
ProcessStoppingState = "stopping"
|
|
|
|
)
|
|
|
|
|
2019-03-25 00:27:14 +00:00
|
|
|
// Defines the basic interface that all environments need to implement so that
|
|
|
|
// a server can be properly controlled.
|
2020-08-11 04:38:42 +00:00
|
|
|
type ProcessEnvironment interface {
|
2019-04-06 19:27:44 +00:00
|
|
|
// Returns the name of the environment.
|
|
|
|
Type() string
|
|
|
|
|
2020-08-28 04:08:33 +00:00
|
|
|
// Returns the environment configuration to the caller.
|
|
|
|
Config() *Configuration
|
|
|
|
|
2020-08-11 04:38:42 +00:00
|
|
|
// Returns an event emitter instance that can be hooked into to listen for different
|
|
|
|
// events that are fired by the environment. This should not allow someone to publish
|
|
|
|
// events, only subscribe to them.
|
|
|
|
Events() *events.EventBus
|
|
|
|
|
|
|
|
// Determines if the server instance exists. For example, in a docker environment
|
|
|
|
// this should confirm that the container is created and in a bootable state. In
|
|
|
|
// a basic CLI environment this can probably just return true right away.
|
|
|
|
Exists() (bool, error)
|
|
|
|
|
2019-04-20 23:20:08 +00:00
|
|
|
// Determines if the environment is currently active and running a server process
|
|
|
|
// for this specific server instance.
|
|
|
|
IsRunning() (bool, error)
|
|
|
|
|
2019-11-24 23:08:38 +00:00
|
|
|
// Performs an update of server resource limits without actually stopping the server
|
|
|
|
// process. This only executes if the environment supports it, otherwise it is
|
|
|
|
// a no-op.
|
|
|
|
InSituUpdate() error
|
|
|
|
|
2019-09-23 03:47:38 +00:00
|
|
|
// Runs before the environment is started. If an error is returned starting will
|
|
|
|
// not occur, otherwise proceeds as normal.
|
|
|
|
OnBeforeStart() error
|
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
// Starts a server instance. If the server instance is not in a state where it
|
|
|
|
// can be started an error should be returned.
|
|
|
|
Start() error
|
2019-03-25 00:27:14 +00:00
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
// Stops a server instance. If the server is already stopped an error should
|
|
|
|
// not be returned.
|
|
|
|
Stop() error
|
2019-03-25 00:27:14 +00:00
|
|
|
|
2020-04-03 20:43:13 +00:00
|
|
|
// Waits for a server instance to stop gracefully. If the server is still detected
|
|
|
|
// as running after seconds, an error will be returned, or the server will be terminated
|
|
|
|
// depending on the value of the second argument.
|
2020-08-14 04:10:33 +00:00
|
|
|
WaitForStop(seconds uint, terminate bool) error
|
2020-04-03 20:43:13 +00:00
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
// Terminates a running server instance using the provided signal. If the server
|
|
|
|
// is not running no error should be returned.
|
|
|
|
Terminate(signal os.Signal) error
|
2019-04-04 05:01:11 +00:00
|
|
|
|
2019-12-22 07:23:56 +00:00
|
|
|
// Destroys the environment removing any containers that were created (in Docker
|
|
|
|
// environments at least).
|
|
|
|
Destroy() error
|
|
|
|
|
2019-12-01 00:43:18 +00:00
|
|
|
// Returns the exit state of the process. The first result is the exit code, the second
|
|
|
|
// determines if the process was killed by the system OOM killer.
|
|
|
|
ExitState() (uint32, bool, error)
|
|
|
|
|
2019-04-04 05:01:11 +00:00
|
|
|
// Creates the necessary environment for running the server process. For example,
|
|
|
|
// in the Docker environment create will create a new container instance for the
|
|
|
|
// server.
|
|
|
|
Create() error
|
2019-04-06 19:27:44 +00:00
|
|
|
|
|
|
|
// Attaches to the server console environment and allows piping the output to a
|
2019-04-20 23:20:08 +00:00
|
|
|
// websocket or other internal tool to monitor output. Also allows you to later
|
|
|
|
// send data into the environment's stdin.
|
|
|
|
Attach() error
|
|
|
|
|
|
|
|
// Sends the provided command to the running server instance.
|
|
|
|
SendCommand(string) error
|
2019-04-06 19:27:44 +00:00
|
|
|
|
|
|
|
// Reads the log file for the process from the end backwards until the provided
|
2020-09-07 20:04:56 +00:00
|
|
|
// number of lines is met.
|
|
|
|
Readlog(int) ([]string, error)
|
2019-04-04 05:01:11 +00:00
|
|
|
}
|