Skip to content

Commit 56c4c95

Browse files
authored
examples: podman quadlet example (#4099)
1 parent 47efe3e commit 56c4c95

5 files changed

Lines changed: 106 additions & 0 deletions

File tree

examples/podman-quadlets/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Podman Quadlet Example
2+
3+
This example demonstrates how to deploy multiple autoscaling minecraft servers behind mc-router with [podman quadlets](https://docs.podman.io/en/stable/markdown/podman-systemd.unit.5.html).
4+
5+
The commands listed below assume rootless podman but can easily be modified for rootful.
6+
7+
## mc-router.host label
8+
9+
In `mc@.container`, replace `example.com` with your domain.
10+
11+
## Server instance configuration
12+
13+
Each server instance requries an environment file with a matching name in the mc folder; e.g. instance `example` uses `mc/example.env`.[^1]
14+
15+
## Container auto-removal fix
16+
17+
Once the quadlets files are installed and daemon-reloaded, the generated service file needs to be edited due to generated quadlets always adding `--rm`.[^2]
18+
To fix this, run `systemctl --user edit mc@.service` and replace the `ExecStart` entry with a copy that substitues `--restart=unless-stopped` where `--rm` is.
19+
The drop-in should look something like this:
20+
21+
```ini
22+
[Service]
23+
ExecStart=
24+
ExecStart=/usr/bin/podman run --name %p-%i --replace --restart=unless-stopped ...
25+
```
26+
27+
## Start containers/services
28+
29+
```sh
30+
systemctl --user enable --now podman.socket
31+
systemctl --user start mc@example.service mc-router.service
32+
# instances are enabled by symlinking from the template
33+
ln -s ${XDG_CONFIG_HOME}/containers/systemd/mc@.service ${XDG_CONFIG_HOME}/containers/systemd/mc@example.service
34+
```
35+
36+
## Rootless notes
37+
38+
If running rootless, be sure to enable lingering with `sudo loginctl enable-linger $USER`.
39+
40+
Also note that source IPs are currently lost due to how rootless podman handles custom networks.
41+
This should be fixed in a future podman release.[^3]
42+
43+
[^1]: The base config is a [template file](https://docs.podman.io/en/stable/markdown/podman-systemd.unit.5.html#template-files) with instance names after the @ sign .
44+
[^2]: <https://github.com/podman-container-tools/podman/discussions/28837>
45+
[^3]: <https://github.com/podman-container-tools/podman/pull/28478>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[Unit]
2+
Description=Minecraft proxy with autoscaling support
3+
4+
[Container]
5+
Image=docker.io/itzg/mc-router
6+
ContainerName=%N
7+
AutoUpdate=registry
8+
UserNS=host
9+
Volume=%t/podman/podman.sock:/var/run/docker.sock:ro
10+
Network=minecraft.network
11+
PublishPort=25565:25565
12+
SecurityLabelDisable=true
13+
Environment=\
14+
"IN_DOCKER=true" \
15+
"AUTO_SCALE_DOWN=true" \
16+
"AUTO_SCALE_UP=true" \
17+
"AUTO_SCALE_DOWN_AFTER=10m" \
18+
"AUTO_SCALE_ASLEEP_MOTD='Server is asleep. Join again to wake it up!'"
19+
20+
[Service]
21+
Restart=always
22+
23+
[Install]
24+
WantedBy=default.target
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# General options
2+
INIT_MEMORY=1G
3+
MAX_MEMORY=4G
4+
5+
# Server options
6+
EULA=TRUE
7+
VIEW_DISTANCE=16
8+
DIFFICULTY=normal
9+
MOTD=Example Server!\nRunning version %VERSION%
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[Unit]
2+
Description=Minecraft server instance
3+
Before=mc-router.service
4+
5+
[Container]
6+
Image=docker.io/itzg/minecraft-server
7+
ContainerName=%p-%i
8+
AutoUpdate=registry
9+
UserNS=auto
10+
Volume=%p-%i:/data:Z,U
11+
Network=minecraft.network
12+
PodmanArgs=--tty --interactive
13+
HealthCmd="/usr/local/bin/mc-health"
14+
HealthInterval=10s
15+
HealthRetries=20
16+
HealthStartPeriod=1m
17+
HealthTimeout=10s
18+
Label=mc-router.host=%p-%i.example.com
19+
EnvironmentFile=./mc/%i.env
20+
21+
[Service]
22+
Restart=on-abnormal
23+
RemainAfterExit=yes
24+
25+
[Install]
26+
WantedBy=default.target
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Network]
2+
Driver=bridge

0 commit comments

Comments
 (0)