# Podman Template

- [Podman Template](#podman-template)
  - [Install minecraft](#install-minecraft)
    - [Create the minecraft user](#create-the-minecraft-user)
    - [Convert Compose to Quadlet](#convert-compose-to-quadlet)
    - [Install Quadlets](#install-quadlets)
    - [Upgrade Quadlets](#upgrade-quadlets)
  - [Expose minecraft](#expose-minecraft)
  - [Backup minecraft](#backup-minecraft)

## Install minecraft

Find and replace minecraft with the name of the service.

### Create the minecraft user

```bash
# SSH into your podman server as root
useradd minecraft
loginctl enable-linger $(id -u minecraft)
systemctl --user --machine=minecraft@.host enable podman-restart
systemctl --user --machine=minecraft@.host enable --now podman.socket
mkdir -p /home/minecraft/.config/containers/systemd
```

### Convert Compose to Quadlet

Create a folder called `quadlets` in your podman_minecraft project.

```bash
# Generate the systemd service
podman run \
--security-opt label=disable \
--userns keep-id \
--rm \
-v $(pwd)/active/container_minecraft:/compose \
-v $(pwd)/active/container_minecraft/quadlets:/quadlets \
quay.io/k9withabone/podlet \
-f /quadlets \
-i \
--overwrite \
compose /compose/compose.yaml

# Copy the files to the server
scp -r active/container_minecraft/quadlets/. minecraft:~/.config/containers/systemd/
```

### Install Quadlets

```bash
ssh minecraft

export GAME_SERVER_NAME=testcraft
mkdir $GAME_SERVER_NAME

# Download the server jar (only needed once)
podman run \
-it \
--rm \
-e SERVER_VERSION=1.21.8 \
-v $(pwd)/$GAME_SERVER_NAME:/downloads \
--security-opt label=disable \
--userns keep-id \
docker.io/ducoterra/get-minecraft:latest

systemctl --user daemon-reload
systemctl --user restart $GAME_SERVER_NAME
```

### Upgrade Quadlets

```bash
scp -r quadlets/. minecraft:~/.config/containers/systemd/
ssh minecraft systemctl --user daemon-reload
ssh minecraft systemctl --user restart minecraft
```

## Expose minecraft

1. Create your minecraft ddns record first [following these docs](/active/container_ddns/ddns.md#)
2. Create a SRV record in your DNS provider like the following:

    active/container_minecraft/secrets/reeseapps_records.json:

    ```json
    {
        "Comment": "CREATE/UPSERT/DELETE a record ",
        "Changes": [
            {
                "Action": "UPSERT",
                "ResourceRecordSet": {
                    "Name": "_minecraft._tcp.testcraft.reeseapps.com",
                    "Type": "SRV",
                    "TTL": 300,
                    "ResourceRecords": [
                        {
                            "Value": "0 5 25566 minecraft.reeseapps.com"
                        }
                    ]
                }
            }
        ]
    }
    ```

    ```bash
    aws route53 change-resource-record-sets --hosted-zone-id $(cat active/aws_route53/secrets/reeseapps-zoneid) --change-batch file://active/container_minecraft/secrets/reeseapps_records.json
    ```

3. Test your record with `nslookup`

    ```bash
    nslookup -q=srv _minecraft._tcp.testcraft.reeseapps.com
    ```

4. Access your server at your domain "testcraft.reeseapps.com"

## Backup minecraft

Follow the Borg [Create a Backup Service Docs](/active/systemd_borg/borg.md#create-a-backup-service)
