2019-04-04 05:01:11 +00:00
|
|
|
package server
|
2019-03-25 00:27:14 +00:00
|
|
|
|
|
|
|
import (
|
2019-03-25 01:00:21 +00:00
|
|
|
"os"
|
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.
|
|
|
|
type Environment interface {
|
2019-04-06 19:27:44 +00:00
|
|
|
// Returns the name of the environment.
|
|
|
|
Type() string
|
|
|
|
|
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-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
|
|
|
|
2019-03-25 01:00:21 +00:00
|
|
|
// 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.
|
2019-04-20 23:20:08 +00:00
|
|
|
Exists() (bool, error)
|
2019-03-25 00:27:14 +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
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// Follows the output from the server console and will begin piping the output to
|
|
|
|
// the server's emitter.
|
|
|
|
FollowConsoleOutput() 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
|
|
|
|
// number of bytes is met.
|
|
|
|
Readlog(int64) ([]string, error)
|
2019-08-17 20:19:56 +00:00
|
|
|
|
|
|
|
// Polls the given environment for resource usage of the server when the process
|
|
|
|
// is running.
|
|
|
|
EnableResourcePolling() error
|
|
|
|
|
|
|
|
// Disables the polling operation for resource usage and sets the required values
|
|
|
|
// to 0 in the server resource usage struct.
|
|
|
|
DisableResourcePolling() error
|
2019-04-04 05:01:11 +00:00
|
|
|
}
|