mc-server-manager/README.md

89 lines
3.4 KiB
Markdown

# mc-server-manager
Simple web server where players can see a list of available servers, player
counts, and request to turn on a server if they have a passcode.
It consists of two components: a web server, and an agent program that runs on
the minecraft server hardware itself.
## Web Server
The web server's responsibility is to show the latest server status information
and provide a way for players to request to turn on a server.
The server is built using [handy-http](https://github.com/andrewlalis/handy-httpd).
In addition to serving the web app from the associated `app` directory, the
following API endpoints are defined:
* POST `/api/servers` - for the agent to send the latest server status info.
* GET `/api/servers` - for clients to fetch the latest server status.
* POST `/api/servers/:id/requests` - for clients to request a server startup.
* GET `/api/server-requests` - for the agent to get a list of requested servers.
### Deployment
This application is deployed to run under a reverse proxy, like Nginx. Call the
`deploy-web.sh` script to deploy it to Andrew's main server.
Also, create an `api-config.properties` file in the server's working directory,
and populated it with values like so:
```properties
agentKey=superSecretAgentKey
clientKey=superSecretClientKey
discordWebhookUrl=https://discord.com/api/webhooks/1234
```
## Agent
The agent will periodically inspect the status of all servers, and send that
data to the web server. The agent will also automatically shutdown servers
that have been inactive for more than a configured time (see **Deployment**
below for how to configure that).
More precisely, the agent will activate periodically, and each time perform the
following activites:
* Send the latest server status information to the web server.
* Use an *idle-tracker* file to determine the amount of time a server has been
*idle* (on, with no players active).
* If the server is idle, but doesn't yet have a tracker file, one is created.
* If the server has at least one player, any existing tracker file is removed.
* If the server is idle and there's a tracker file present, and the tracker
file is at least 15 minutes old, then the server is shut down.
* Get the list of requested servers to start from the web, and start each server.
### Deployment
This agent is simply deployed to the physical server where the minecraft
servers are installed, and it is linked as a SystemD service (but not enabled),
and then a SystemD timer is activated to trigger it to run every so often.
Run `deploy-agent.sh` to deploy the agent to the server.
You should make sure there's an `agent-config.properties` file with the
following values:
```properties
webUrl=https://mc-servers.andrewlalis.com
discordWebhookUrl=https://discord.com/api/webhooks/1234
agentKey=superSecretAgentKey
serverInactivityTimeoutMinutes=30
```
And additionally, a `servers.json` file to define the servers that the agent
will control, formatted like so:
```json
[
{
"name": "survival-server",
"displayName": "My Survival Server",
"directory": "/home/andrew/minecraft/servers/survival",
"description": "My personal survival server."
},
{
"name": "creative-server",
"displayName": "My Creative Server",
"directory": "/home/andrew/minecraft/servers/creative",
"description": "A creative server for me to mess around in."
}
]
```