minecraft-server-playbook.md

#406
Raw
Author
winny
Created
Nov. 5, 2021, 1:12 a.m.
Expires
Never
Size
1.8 KB
Hits
447
Syntax
markdown
Private
✗ No
You are viewing the source code of this paste. Click "Render" to see the formatted version.
# Pre steps

1. Add your login user
2. Ensure your user can run `sudo -i` to gain root (e.g. `gpasswd -a youruser sudo`).
3. Install your ssh key to the new user (e.g. `sudo -u youruser -i` then `umask 077; mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys` paste in your key, then type `^D`).
4. Try logging in.
5. Add `PasswordAuthentication no` to `/etc/ssh/sshd_config`
6. Maybe add your user to a special group, then add that gorup to `/etc/ssh/sshd_config` like so `AllowGroups yourspecialgroup`
7. `sudo systemctl reload ssh`
8. verify login still works

# Set up your login user and the service account

`sudo useradd -m -s /bin/bash minecraft`

Then log into it via `sudo -u minecraft -i`.

# New user files

In your new user add this to homedir, create the following files:

## `start.sh`

    #!/usr/bin/env bash
    set -eu
    . "${0%/*}/defaults.sh"
    cd "$1"
    [[ -r config.sh ]] && . config.sh
    rlwrap java -Xmx${memmax} -Xms${memmin} -jar ~/jars/minecraft_server.${version}.jar nogui

## `defaults.sh`

    version=1.17.1
    memmax=1024M
    memmin=512M

## `jars/`

Create a `jars/` folder, download your `minecraft_server.X.Y.Z.jar` files here.

Example:

    wget -o jars/minecraft_server.1.17.1.jar \
        https://launcher.mojang.com/v1/objects/a16d67e5807f57fc4e550299cf20226194497dc2/server.jar


## `worlds/`

Create a `worlds/` folder.  Create a folder for your world in that folder - e.g. `worlds/main/`.  Populate `config.sh` if you want to override stuff.

    memmax=3500M
    memmin=2500M

(Tuned for a vultr 4GB VPS with 2x cpu)

# Starting

After setting up the files, log into your user via `sudo -u minecraft -i` then run `tmux new -s minecraft ./start.sh worlds/main` then detach using `C-b d`.

# TODO

systemd unit for tmux minecraft.