Jump to content

Forums Announcement

Read-Only Mode for Announcements & Changelogs

Dear Survivors, we'd like to inform you that this forum will transition to read-only mode. From now on, it will serve exclusively as a platform for official announcements and changelogs.

For all community discussions, debates, and engagement, we encourage you to join us on our social media platforms: Discord, Twitter/X, Facebook.

Thank you for being a valued part of our community. We look forward to connecting with you on our other channels!

Stay safe out there,
Your DayZ Team

Sign in to follow this  
Ivan Connor

Dayz Server Linux - Service For Restart Cycle

Recommended Posts

After installing steamcmd and the DayZ server on Linux, the restart cycle can be configured through a server shutdown time in messages.xml.
To restart the DayZ server software automatically after a timed shutdown a Linux service is needed.
This is a systemd configuration file of a DayZ Service on a Linux Server. The DayZServer startup command itself is pretty much the same, as always.
The nice value is set to -19, so that the OS treats the DayZ service with the highest priority possible. In this thread I will describe controlling the service and other details.

File Name And Path:
/lib/systemd/system/dayz-server.service

Content Of The File:
[Unit]
Description=DayZ Dedicated Server
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target
StartLimitIntervalSec=600
StartLimitBurst=3

[Service]
Type=exec
ExecStartPre=/home/dayzserver/servers/dayz-server/update.sh
ExecStart=/home/dayzserver/servers/dayz-server/DayZServer "-mod=3364216187;3038576574;2832884779;2602208478;2950097655;1646187754;" "-serverMod=2472500243" -cpuCount=8 -BEpath=battleye -profiles=profiles -config=serverDZ.cfg -port=2302 -dologs
WorkingDirectory=/home/dayzserver/servers/dayz-server/
LimitNOFILE=100000
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s INT $MAINPID
User=dayzserver
Group=dayzserver
Restart=on-failure
RestartSec=10s
TimeoutSec=600s
Nice=-19

[Install]
WantedBy=multi-user.target

Share this post


Link to post
Share on other sites
Posted (edited)

The commands to control the DayZ systemd service are as follows:

"systemctl enable dayz-server" -> Enables and installs the service

"systemctl stop dayz-server" -> Stops the DayZ Server
"systemctl start dayz-server" -> Starts the DayZ Server

"systemctl daemon-reload" -> Reloads the service configuration after changes, like when adding mods
"systemctl reset-failed" -> Resets the "failed" counter when there's a prob and max retries were reached

________________________________________________________________________________________________________________________________

The systemd service configuration also has a "ExecStartPre" parameter, which can be used to execute a script before service startup.

It can be used to backup the world and to check for server and mod updates. Note: The scripts have to be executable or service startup will fail without a specific error.

Here are examples for two shell scripts to backup the world (and delete old logfiles) and to check for updates.

________________________________________________________________________________________________________________________________

Script Name: update.sh

Content:

#!/bin/bash

# backup dz mission & gameworld

min=$(date "+%Y%m%d_%H%M%S");

# Create Dirs

mkdir -p /home/dayzserver/BACKUP_WORLD/$min

mkdir -p /home/dayzserver/BACKUP_WORLD/$min/logs

cp -r /home/dayzserver/servers/exp-dayz-server/mpmissions/dayzOffline.sakhal /home/dayzserver/BACKUP_WORLD/$min

# delete world backups older than a week

find /home/dayzserver/BACKUP_WORLD/* -mtime +7 -exec rm -rf {} \;

# backup dz server log files

cp /home/dayzserver/servers/exp-dayz-server/profiles/* /home/dayzserver/BACKUP_WORLD/$min/logs

#cp /home/dayzserver/servers/exp-dayz-server/profiles/VPPAdminTools/Logging/* /home/dayzserver/BACKUP_WORLD/$min/logs

#cp -r /home/dayzserver/servers/exp-dayz-server/profiles/CodeLock/Logs/* /home/dayzserver/BACKUP_WORLD/$min/logs

# delete dz server log files

rm -f /home/dayzserver/servers/exp-dayz-server/profiles/*.log

rm -f /home/dayzserver/servers/exp-dayz-server/profiles/*.RPT

rm -f /home/dayzserver/servers/exp-dayz-server/profiles/*.mdmp

#rm -f /home/dayzserver/servers/exp-dayz-server/profiles/VPPAdminTools/Logging/*.txt

#find /home/dayzserver/servers/exp-dayz-server/profiles/CodeLock/Logs -maxdepth 1 -mindepth 1 -mtime +1 -exec rm -f {} \;

# Make Tarball Of DZ Backup Dir

tar -czvf /home/dayzserver/BACKUP_WORLD/$min.tar.gz /home/dayzserver/BACKUP_WORLD/$min

# Delete Backup Dir

rm -rf /home/dayzserver/BACKUP_WORLD/$min

# Make Tarball Of Full Server

#tar -czvf /home/dayzserver/BACKUP_WORLD/dayzserver_20240506.tar.gz /home/dayzserver/servers/exp-dayz-server

#check for dz server and mod updates

/home/dayzserver/servers/exp-dayz-server/update_mods.sh

________________________________________________________________________________________________________________________________

As one can see, the last line calls the script that checks for updates. When I am working on the server I often deactivate it with a comment # because the update checks take some time.

________________________________________________________________________________________________________________________________

Script Name: update_mods.sh

Content:

#!/bin/bash

#check for server update

/home/dayzserver/servers/steamcmd/steamcmd.sh +force_install_dir /home/dayzserver/servers/dayz-server/ +login YourSteamUser +app_update 223350 +quit

#check for mods update

/home/dayzserver/servers/steamcmd/steamcmd.sh +force_install_dir /home/dayzserver/servers/dayz-server/ +login YourSteamUser +app_update 223350 +workshop_download_item 221100 3467647389 +quit

/home/dayzserver/servers/steamcmd/steamcmd.sh +force_install_dir /home/dayzserver/servers/dayz-server/ +login YourSteamUser +app_update 223350 +workshop_download_item 221100 1646187754 +quit

/home/dayzserver/servers/steamcmd/steamcmd.sh +force_install_dir /home/dayzserver/servers/dayz-server/ +login YourSteamUser +app_update 223350 +workshop_download_item 221100 2950097655 +quit

/home/dayzserver/servers/steamcmd/steamcmd.sh +force_install_dir /home/dayzserver/servers/dayz-server/ +login YourSteamUser +app_update 223350 +workshop_download_item 221100 2602208478 +quit

/home/dayzserver/servers/steamcmd/steamcmd.sh +force_install_dir /home/dayzserver/servers/dayz-server/ +login YourSteamUser +app_update 223350 +workshop_download_item 221100 2832884779 +quit

/home/dayzserver/servers/steamcmd/steamcmd.sh +force_install_dir /home/dayzserver/servers/dayz-server/ +login YourSteamUser +app_update 223350 +workshop_download_item 221100 3038576574 +quit

/home/dayzserver/servers/steamcmd/steamcmd.sh +force_install_dir /home/dayzserver/servers/dayz-server/ +login YourSteamUser +app_update 223350 +workshop_download_item 221100 3364216187 +quit

/home/dayzserver/servers/steamcmd/steamcmd.sh +force_install_dir /home/dayzserver/servers/dayz-server/ +login YourSteamUser +app_update 223350 +workshop_download_item 221100 2472500243 +quit

________________________________________________________________________________________________________________________________

Note: I use a 2nd Steam account with another copy of DayZ for the server to avoid authorization issues.

Edited by Ivan Connor

Share this post


Link to post
Share on other sites
Sign in to follow this  

×