A Python daemon for managing Minecraft servers.
Discord is used for controlling the server, and seeing its current status.
See the official docs.
- Create a Discord account (or use an existing one)
- Create a Discord application with the given account
- Make the application into a bot (= create a bot account for the application)
- Invite the bot to the server it will be controlled from. Bot permissions:
- View channels
- Read message history
- Send messages
- Add reactions
Google Drive is used to keep copies of savefiles (usually the Minecraft world folder).
- Create a Google account (or use an existing one)
- From the developer dashboard:
- Create a new application and select it
- Enable the Google Drive API for the application
- Register a service account
- Generate a key for the service account and download it. Keep the downloaded JSON safe!
- From Google Drive:
- Create a folder
- This is called the "root folder" in the code; save files will go here
- Share the folder with the service account
- Like you would with a
meatbagperson; just share it with the service account's email - Service account must be "Editor" (read + write permissions)
- Like you would with a
- Create a folder
- Wait a few minutes until Drive API is enabled - API calls will fail in the meantime!
- Install prerequisites:
# pacman -S sudo python python-pip python-virtualenv
- Create a user exclusively for running Minecraft:
# useradd --home=/mc -m --shell=/usr/bin/nologin mc
# cd /mc
(optionally mount /mc
to a dedicated BTRFS subvolume or partition)
3. Launch a shell as the new user:
# sudo -u mc $SHELL
$
- Clone this repo:
$ git clone https://github.com/UberLambda/cieloblocco
$ cd cieloblocco
- Create a virtualenv and install Python dependencies:
$ virtualenv venv
$ source venv/bin/activate
(venv) $ pip install -r requirements.txt
- Setup a server
- Download a server pack (.zip) and/or installer script
- Unzip/install the pack somewhere in
/mc
(e.g./mc/mypack
) - Configure
/mc/mypack/server.properties
appropriately - Tweak any supplied
ServerStart.sh
script- Remove all infinite loops / readline calls / user interaction
- Disable GUI (
nogui
) - Change Java memory flags appropriately (
-Xms
,-Xmx
, ...)
chmod +x ServerStart.sh
- (Optional) Start the server; check if everything is working
- (Optional)
/op <Player>
via the server's console as needed
- Symlink the current server folder (for whatever modpack) to
/mc/current
- Create a /etc/cieloblocco/envfile (in Systemd
EnvironmentFile=
format)- Configure
key=value
environment variable pairs, as needed by CieloBlocco - Or:
systemctl edit cieloblocco.service
(see(9)
), and add environment variables in manually - Crucial environment variables:
CB_GAME_SERVER_PATH
: Path to the server (e.g./mc/current
)CB_GAME_STARTUP_SCRIPT
: Relative path to the startup script (e.g.ServerStart.sh
)CB_GAME_SAVE_FOLDER
: Relative path to world / save files (e.g.world
)CB_DISCORD_TOKEN
: Token (secret!) for the Discord botCB_DISCORD_CHANNEL_ID
: Discord ID of the text channel the bot is to send messages toCB_GDRIVE_CRED
: Path to the GDrive service account key .jsonCB_GDRIVE_ROOT_ID
: File ID of the folder shared with the service accountCB_GAME_CONTROL
: To setup rcon if needed (see the help of theenv.Var
)
- Configure
- Copy the GDrive service account key .json to /etc/cieloblocco
- And change its owner to
mc
, since the Python script (which is run by themc
user) needs to access it!
- And change its owner to
- Create a systemd unit for the service, e.g.:
[Unit]
Description=CieloBlocco server
After=network.target network-online.target nss-lookup.target
[Service]
EnvironmentFile=/etc/cieloblocco/envfile
RuntimeDirectory=/mc
Exec=/mc/cieloblocco/venv/bin/python -m cieloblocco
User=mc
Group=mc
ProtectSystem=on
ProtectHome=on
[Install]
WantedBy=multi-user.target
- Start the server:
# systemctl enable cieloblocco
- Or
systemctl enable --now cieloblocco
to make the server start with the (virtual) machine - The bot should now connect to the Discord channel; click on the "Server running" message's reaction to stop the server. The world is zipped and copied to GDrive immediately after the server is stopped.