Follow the directions on the PZwiki to setup a Project Zomboid server. Upon completion of that guide the Zomboid Server will be installed in /opt/pzserver/
Commands will be sent to the server via its RCON interface. A reliable RCON interface is rcon-cli. rcon-cli is not available through Ubuntu's software repositories and will be acquired through github.
The following commands will download rcon-cli
, extract the downloaded archive, change the name of the resultant directory from rcon-0.10.3-amd64_linux
to just rcon
, and finally it will change the ownership of rcon to pzuser.
root@server # cd /opt/pzserver && wget https://github.com/gorcon/rcon-cli/releases/download/v0.10.3/rcon-0.10.3-amd64_linux.tar.gz && tar xf rcon-0.10.3-amd64_linux.tar.gz && mv rcon-0.10.3-amd64_linux rcon && chown -R pzuser:pzuser rcon
Edit the configuration file /opt/pzserver/rcon/rcon.yaml
so that there is a zomboid
entry with the correct server details. The port will need to be changed if the server is operating on non standard ports.
default: address: "" # host:port, for example 127.0.0.1:16260 password: "" log: "rcon-default.log" type: "" # rcon, telnet, web. timeout: "10s" zomboid: address: "127.0.0.1:16261" password: "your_server_admin_password_here" timeout: "10s" log: "rcon-zomboid.log"
This configuration file can be tested with the following command as pzuser
.
pzuser@server $ cd /opt/pzserver/rcon && ./rcon -e zomboid "servermsg \"test\""
The command will return Message sent.
to the terminal while players on the server will see the test
server message.
Two scripts will be used to reboot the zomboid server. The first of which will inform players of the impending reboot every minute for five minutes. Once players are notified, it calls a shutdown script located in the same directory.
Create the following file /opt/pzserver/rcon/zomboid-reboot.sh
with the following contents.
#!/bin/bash SHUTDOWN_TIMER_MIN=5; #Every minute this script will send the users a message via RCON that the server is rebooting in n minutes. cd "$(dirname "$0")"; for ((i = $SHUTDOWN_TIMER_MIN; i > 0; i--)); do MSG="Rebooting the server in ${i} "; if [[ i -eq 1 ]] then MSG+="minute."; else MSG+="minutes."; fi ./rcon -e zomboid "servermsg \"${MSG}\""; sleep 60; done ./zomboid-shutdown.sh
Create the second script file /opt/pzserver/rcon/zomboid-shutdown.sh
which will reboot the server by issuing RCON save
and quit
commands.
#!/bin/bash cd "$(dirname "$0")"; ./rcon -e zomboid "save"; ./rcon -e zomboid "quit"; sleep 20; timestamp=$(date +%Y%m%d_%H%M%S); echo -en "${timestamp} : Server is shutdown\n" >> shutdown.txt;
Change the permissions of zomboid-shutdown.sh
and zomboid-reboot.sh
so that the scripts are executable.
root@server # chmod +x /opt/pzserver/rcon/zomboid-shutdown.sh /opt/pzserver/rcon/zomboid-reboot.sh
These scripts can be executed on their own, however having scheduled server reboots is desirable for hands-off administration.
Create the systemd service file /etc/systemd/system/zombiod.service
to launch the Project Zomboid server. When this service is started, it will always ensure that the Project Zomboid server is running.
[Unit] Description=Start the Project Zomboid Service Requires=network-online.target After=network-online.target [Service] Type=simple Restart=always RestartSec=10 User=pzuser Group=pzuser WorkingDirectory=/opt/pzserver/ ExecStart=/opt/pzserver/start-server.sh -servername doltpocalypse ExecStop=/opt/pzserver/rcon/zomboid-shutdown.sh [Install] WantedBy=multi-user.target
Create the systemd service file /etc/systemd/system/zomboid-reboot.service
. This service file handles the server reboot process.
[Unit] Description=Reboot the Project Zomboid Server via RCON in /opt/pzserver/rcon [Service] Type=oneshot User=pzuser Group=pzuser WorkingDirectory=/opt/pzserver/rcon/ ExecStart=/opt/pzserver/rcon/zomboid-reboot.sh
Lastly, create a systemd timer file /etc/systemd/system/zomboid-reboot.timer
which executes the zomboid-reboot.service
every four hours.
[Unit] Description=Functions as a timer for zomboid-reboot.service. [Timer] Unit=zomboid-reboot.service OnCalendar=00/4:00 [Install] WantedBy=timers.target
Start and enable the zomboid.service
and the zomboid-reboot.timer
services.
root@server # systemctl enable --now zomboid.service root@server # systemctl enable --now zomboid-reboot.timer
The Project Zomboid server now reboots every four hours and warns players before a reboot.