Service modules

A service module is the module type that runs a game or voice server. Every service in GameDash is tied to one, and that module is in full control of how the service behaves — from first-time setup through to mod installs.

Resources

Most service modules expose more than one resource. The two you will almost always implement are setup and process handling.

Resources are declared in the module's properties.json. If a resource is not declared, the platform executes its own default behaviour where one exists — so a game that installs through SteamCMD and starts with a single executable needs very little of its own code.

The process resource

This is the core of a service module. It extends the process template and implements four methods.

start() — create a child process and spawn it. Use createDefault() rather than building one from scratch: it sets platform defaults for you, including the instance's relay channel, which is what makes console output reach the browser.

$ChildProcess = $this->Instance->getProcess()->getChildProcesses()->createDefault();

Then set the executable and arguments, and spawn. Arguments usually come from the instance's settings, which were populated during setup.

stop() — stop cleanly. Most games want warning and a save before the process goes away, which means sending console input before stopping the process:

$Console = $this->Instance->getConsole();

$Console->getIo()->getInput()->send('say Server will shut down in 5 seconds');
$Console->getIo()->getInput()->send('save-all');

Then stop the child process. Expect it to already be gone — catching ChildProcessNotRunningException and treating it as success is normal, not defensive programming.

restart() — where a game supports an in-place restart. Leave it empty to inherit default behaviour.

isOnline() — report whether the server is running. Check that the instance has a process id at all before asking about it; an instance that has never started has nothing to look up. Treat ChildProcessNotFoundException as "not running" rather than as an error.

usageIsMeasurable() — return true to mark the process's resource usage as measurable, so the panel can chart CPU and memory for the instance.

Settings

Settings created during setup are readable from the instance:

$this->Instance->getSettings()->get('jar')->getValue();

This is how a start command stays generic: the module reads which jar, which map, which port from settings rather than hard-coding them, and operators change them in the panel.

Operating systems

Declare supportedOperatingSystem honestly — see Anatomy of a module. The panel uses it to decide which nodes may host the game.

A complete one

Example service module shows all of this working together for Minecraft.