Code Monkey home page Code Monkey logo

project-zomboid-container's Introduction

Zomboid SigTerm Wrapper

This is a neat wrapper around project zomboid which ensures it exits gracefully upon receiving a sigterm signal, meaning it becomes easier to run as a service on servers with e.g. systemd. It is recommended to run this as a docker or podman container.

This exists since Zomboid doesnt handle termination signals gracefully as of pre 42 (https://theindiestone.com/forums/index.php?/topic/63563-4178-multiplayer-zomboid-dedicated-server-does-not-handle-sigterm/). Prompting the wiki to recommend unreliable hacks where one begs the server to save, waits for 15 seconds and PRAYS it had time to save. This wrapper will exit ONLY when said server has exited cleanly.

How to use

Passing parameters

You can pass parameters directly to the zomboid server in two ways. Firstly using the CUSTOM_SERVER_PARAMETERS environment variable, or directly as an argument to the executable. Both scenarios require the parameters to be passed as one singular string, with each parameter separated by commas (,). I suggest reading the Dockerfile for details.

Installing a server using Docker

The container will install the latest version of project zomboid using steamcmd, with the game files stored inside the container at /install_dir, saves at /saves d logs at /logs by default.

Thus you can build and run the container with persistent server install, saves and logs like the following:

podman run --rm -it -v $PWD/game_files:/install_dir -v $PWD/saves:/saves -v $PWD/logs:/logs -p 16261:16261/udp -p 16262:16262/udp -p 27015:27015/tcp ghcr.io/pommaq/project-zomboid-container:master

Or for a more permanent install, run it as a systemd service:

[Unit]
Description=Project Zomboid Server
After=containerd.service
Wants=network-online.target

[Service]
TimeoutSec=900
Restart=always
ExecStartPre=-/usr/bin/docker  stop -i zomboid

ExecStart=/usr/bin/docker  run --rm --pull=always --name zomboid -v /root/game_files:/install_dir -v /root/save_files:/saves -v /root/logs:/logs -p 16261:16261/udp -p 16262:16262/udp -p 27015:27015/tcp -e CUSTOM_SERVER_PARAMETERS="-adminpassword,password123,-Xms1024m,-Xmx8192m" ghcr.io/pommaq/project-zomboid-container:master

ExecStop=/bin/docker stop zomboid

[Install]
WantedBy=multi-user.target

Standalone

For parameter details, run the binary with --help.

cd tools/runner
cargo run -- --help
# (OR if the runner is installed and added to $PATH)
runner --help

First you will need to manually install zomboid and the wrapper located at tools/runner. Then, assuming zomboid was installed at /install_dir:

# Set admin password using parameters to ensure the server won't prompt us
runner /install_dir/start-server.sh "'-adminpassword,MYCOOLPASSWORD'"

Or as a systemd service, assuming runner was installed as /usr/bin/runner

[Unit]
Description=Project Zomboid Server
Wants=network-online.target

[Service]
TimeoutSec=900
Restart=always
ExecStart=/usr/bin/runner /install_dir/start-server.sh "'-adminpassword,password123,-Xms1024m,-Xmx8192m'"


[Install]
WantedBy=multi-user.target

Configuring Zomboid server

and adding mods etc.

Once the server is installed open the savefile location (e.g. /home/timmy/Zomboid) or Documents/Zomboid where the configuration files will be located as per usual for zomboid.

project-zomboid-container's People

Contributors

pommaq avatar

Watchers

 avatar

project-zomboid-container's Issues

Hitting CTRL+C in a terminal kills server harshly

This is likely related to it creating a subshell, meaning the signal isnt propagated towards the binary.

A workaround is to use the binary "runner" by itself meanwhile. One can look into the dockerfile to see how the installation is performed, and then point it towards the "start-server.sh" file as an argument.

Container size could be smaller

We can likely install the game similarly to how we install the runner in the docker container. Then start a new separate alpine container where we call everything.

The documentation is not good enough

I want documentation regarding how to run the server using only the runner, and for the container. Preferably with systemd service examples and arguments towards WHY this is better compared to what is presented on the wiki atm.
where the following systemd file is recommended:

[Unit]
Description=Project Zomboid Server
After=network.target

[Service]
PrivateTmp=true
Type=simple
User=pzuser
WorkingDirectory=/opt/pzserver/
ExecStart=/bin/sh -c "exec /opt/pzserver/start-server.sh </opt/pzserver/zomboid.control"
ExecStop=/bin/sh -c "echo save > /opt/pzserver/zomboid.control; sleep 15; echo quit > /opt/pzserver/zomboid.control"
Sockets=zomboid.socket
KillSignal=SIGCONT

[Install]
WantedBy=multi-user.target

which is not guaranteed to save before being killed on some machines.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.