Files
2026-09-02 14:47:08 -06:00

43 lines
2.0 KiB
Django/Jinja

# Systemd unit for {{ minecraft.server_name }} Minecraft server running on Podman
# Deployed by Ansible - managed file
[Unit]
Description=Minecraft Server ({{ minecraft.server_name }}) - Podman Container
Documentation=https://hub.docker.com/r/itzg/minecraft-server
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User={{ minecraft_user }}
Group={{ minecraft_user }}
WorkingDirectory={{ paths.data_dir }}
# Pull the image if not present (idempotent)
ExecStartPre=/usr/bin/podman pull {{ podman.image }}:{{ podman.image_tag }}
# Stop existing container before starting
ExecStartPre=-/usr/bin/podman rm -f {{ podman_container_name }}
# Run the Minecraft server in a Podman container
ExecStart=/usr/bin/podman run --name {{ podman_container_name }} --replace --env-file {{ paths.base_dir }}/minecraft.env --volume {{ paths.data_dir }}:/data:Z {% if podman.extra_volumes is defined and podman.extra_volumes %}{% for vol in podman.extra_volumes %}--volume {{ vol }} {% endfor %}{% endif %}{% if podman.memory_limit is defined and podman.memory_limit %}--memory {{ podman.memory_limit }} {% endif %}{% if podman.cpu_shares is defined and podman.cpu_shares %}--cpu-shares {{ podman.cpu_shares }} {% endif %}{% if podman.network_mode == 'host' %}--network host {% else %}--publish {{ minecraft.port }}:{{ minecraft.port }}/tcp {% if minecraft.rcon_enabled %}--publish {{ minecraft.rcon_port }}:{{ minecraft.rcon_port }}/tcp {% endif %}{% endif %}{% for key, value in podman.labels.items() %}--label "{{ key }}={{ value }}" {% endfor %}--log-driver {{ podman.log_driver | default('journald') }} {{ podman.image }}:{{ podman.image_tag }}
# Restart if it crashes (systemd handles restart policy)
Restart=on-failure
RestartSec=15
# Basic process limits
LimitNOFILE=65536
LimitNPROC=4096
# Logging
StandardOutput=journal
StandardError=journal
SyslogIdentifier={{ minecraft.server_name }}
# Allow container to manage its own namespaces/limits
NoNewPrivileges=false
ProtectSystem=false
[Install]
WantedBy=multi-user.target