DayZ
Auto update DayZ server script (app, mods, etc)
Sorry, but not sure where exactly to post and apologies if this post gets messy. Been messing around with my DayZ dedicated server. Wanted to get it fairly automated and used ChatGPT to accomplish this from my basic startup .bat file. Took a while since ChatGPT wants to break what it has already accomplished by changing code when you specifically inform it to utilize the exact same code. Anyways...ChatGPT and a very frustrated me came up with the following batch file that will take a simple mod list (modlist.txt with a mod's numeric id and @modname) and

1. proceed to create a new @mod folder if it doesn't exist
2. use the numeric id and copy the contents from the Workshop folder
3. Update all mods from the modlist.txt in the server directory folder
4. Create a launch parameter mod list for starting the server
5. Loop through each mod folder to copy keys to server key folder (in case new mod added)
6. Start your server with custom parameters
7. Auto restart your server within specified time frame

-----------------------------------------------------------------------------------------------
The main thing that needs to be updated is the modlist.txt file. An example of the format is the following (id @modname):

1559212036 @CF
2545327648 @Dabs Framework
2116157322 @DayZ-Expansion-Licensed
2572331007 @DayZ-Expansion-Bundle
1828439124 @VPPAdminTools
------------------------------------------------------------------------------------------------

Here is some recommendations that I did for my setup
1. Put my server folder in the root C:\DayZServer
2. Put steamcmd folder in C:\DayZServer. Login once inside the directory and you should not need a password in your .bat file
3.Place modlist.txt in C:\DayZServer
4.Make sure you have Steam installed and logged in on same PC. i have a second copy of DayZ and separate account for this one. May need to disable steam guard to have this work 100%.
5.Be sure to add mods through steam workshop like normal (click + icon). i don't know if this is required because when testing a couple mods that I didn't add via Steam app it still worked.

Here is the .bat code

------------------------------------------------------------------------------------------------
@echo off
setlocal enabledelayedexpansion

:: SteamCMD configuration
set "STEAMCMD_PATH=C:\DayZServer\steamcmd"
:: Set the Steam login credentials
set "STEAM_USERNAME=your_username"
:: Reminder: For security reasons, you might want to input the password during execution.
:: Set the server directory where mods will be installed or updated
set "SERVER_DIR=C:\DayZServer"
:: Path to the modlist file
set "MODLIST_PATH=C:\DayZServer\modlist.txt"
:: DayZ App ID
set "DAYZ_APP_ID=221100"
:: Steam Workshop content directory
set "WORKSHOP_CONTENT_DIR=C:\Program Files (x86)\Steam\steamapps\workshop\content\221100"
::Set Keys Directory
set "KEYS_DIR=%SERVER_DIR%\keys"

:modFoldersAndContent
:: Creating mod folders based on modlist.txt and copying contents from the workshop
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
set "numericID=%%a"
set "modName=%%b"
if not exist "%SERVER_DIR%\%%b\" (
echo Creating missing mod folder: %%b
mkdir "%SERVER_DIR%\%%b"
echo Copying contents for: %%b from !numericID!
xcopy "%WORKSHOP_CONTENT_DIR%\!numericID!\*" "%SERVER_DIR%\%%b\*" /E /I /Y
)
)

:: Update mods using SteamCMD
echo Updating DayZ Mods...
:: Initialize SteamCMD script with force_install_dir before login
echo force_install_dir "%SERVER_DIR%" > "%SERVER_DIR%\steamcmd_script.txt"
echo login %STEAM_USERNAME% >> "%SERVER_DIR%\steamcmd_script.txt"
::Add app_update to keep server base updated. Will add significant time to server startup
echo app_update %DAYZ_APP_ID% validate >> "%SERVER_DIR%\steamcmd_script.txt"
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
echo workshop_download_item %DAYZ_APP_ID% %%a >> "%SERVER_DIR%\steamcmd_script.txt"
)
echo quit >> "%SERVER_DIR%\steamcmd_script.txt"
:: Execute the constructed SteamCMD command sequence from a script file
"%STEAMCMD_PATH%\steamcmd.exe" +runscript "%SERVER_DIR%\steamcmd_script.txt"

:: Initialize the mods string for server launch
set "MODS="

:: Construct the mod launch parameter from the modlist
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
set "modFolder=%%b"
set "MODS=!MODS!;!modFolder!"
)

:: Remove the leading semicolon from the mods string
set "MODS=!MODS:~1!"

echo Mods to be loaded: !MODS!

:: Section to copy keys from each mod's keys folder to the server's keys directory
:: Ensure the target keys directory exists
if not exist "%KEYS_DIR%" mkdir "%KEYS_DIR%"

:: Loop through each mod folder to copy keys
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
if exist "%SERVER_DIR%\%%b\keys\*" (
xcopy "%SERVER_DIR%\%%b\keys\*" "%KEYS_DIR%" /E /I /Y
)
)

:start
:: Server configurations
set "serverName=your_server_name"
set "serverLocation=C:\DayZServer"
set "profile=your_profile_name"
set "serverPort=2302"
set "serverConfig=serverDZ.cfg"
set "serverCPU=4"

title %serverName% batch
cd /d "%serverLocation%"
echo (%time%) %serverName% started.


:: Launch parameters
::output to ensure modlist is correct for start command
echo start "DayZ Server" /min DayZServer_x64.exe "-mod=%MODS%" -profiles=%profile% -config=%serverConfig% -port=%serverPort% -cpuCount=%serverCPU% -dologs -adminlog -netlog -freezecheck
start "DayZ Server" /min DayZServer_x64.exe "-mod=%MODS%" -profiles=%profile% -config=%serverConfig% -port=%serverPort% -cpuCount=%serverCPU% -dologs -adminlog -netlog -freezecheck

:: Wait before restarting server process
timeout /t 14400 /nobreak

:: Optionally kill DayZ Server process before restarting
taskkill /im DayZServer_x64.exe /F

goto modFoldersAndContent

------------------------------------------------------------------------------------------------

I'm sure there are more efficient ways of doing this. I was struggling to find info online that wasn't way over my head, so had to go the ChatGPT route.

Please tell me if you recommend any changes or have some questions. I am sure it is overkill. Hope this can help someone with their server.
< >
Affichage des commentaires 1 à 8 sur 8
Looks good to me! (haven't tested it yet), I to wanted to create a .bat file that did exactly this myself when i used to run servers but just didn't have the time. I only had a basic one that copied trader files and .xml loot table files etc so i could edit them while the server was still running, and they would update on restart. I have saved your posted info for later use (also subbed to the discussion). Thank you for sharing :)
Tried it out, so it copies the name of the folder of a mod but doesn't actually move any files into that directory so it ends up being an empty mod essentially.
any way to add in to search for Key folder and add it to Keys?
some mods makers dont make a keys folder and makes a key folder
so it never gets moved/updated

such as the below?


:: Section to copy keys from each mod's keys folder to the server's keys directory
:: Ensure the target keys directory exists
if not exist "%KEYS_DIR%" mkdir "%KEYS_DIR%"

:: Loop through each mod folder to copy keys
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
if exist "%SERVER_DIR%\%%b\keys\*" (
xcopy "%SERVER_DIR%\%%b\keys\*" "%KEYS_DIR%" /E /I /Y
)
)

if not exist "%KEYS_DIR%" mkdir "%KEYS_DIR%"

:: Loop through each mod folder to copy keys
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
if exist "%SERVER_DIR%\%%b\key\*" (
xcopy "%SERVER_DIR%\%%b\key\*" "%KEYS_DIR%" /E /I /Y
)
)
also shouldn't this update the dedicated server client vs the game client?
anyway to change app id and still allow the workshop to update?

i guess add another check for it?
Maisonneuve_Server a écrit :
any way to add in to search for Key folder and add it to Keys?
some mods makers dont make a keys folder and makes a key folder
so it never gets moved/updated
If a Mod on the Workshop does not have a Keys folder (and no Key included), then the mod is not intended for public use, and is a private mod for a specific server owner who has the keys already. You can't just "make up" your own key to use a mod with no key.

If you already have a mod with a key, and the mod works, you don't need to update the key when you update the mod .. keys are assigned to the Mod Author, not the individual mod itself. Example: All my Mods, use the same Key, so if I forget to add the Key to one I upload, all you need to do is use the key from one of my other mods. If you have 2 mods from the same person, they both use one key in the server Keys folder.
Took a little tweaking to get things working the way I wanted for my use case, but this was a great starting point & hidden gem, thanks for sharing!
He just doesn't download the mods for me. What could be the reason? He always gives an ERROR message.
I am so sorry just got back into playing DayZ and wasnt receiving notifications on this thread. i have updated the script. Be sure to verify/change the paths, username, servername, profile, ports, and cpu cores to match your server. New instructions and script below

modlist.txt file format the same. Mods should start at line 1 and each mod must be on a new line
------------------------------------------------------------------------------------------------
1559212036 @CF
2545327648 @Dabs Framework
2116157322 @DayZ-Expansion-Licensed
2572331007 @DayZ-Expansion-Bundle
1828439124 @VPPAdminTools
------------------------------------------------------------------------------------------------

Dont include quotes unless stated
1. Create empty server folder in C:\ directory (C:\DayZServer)
2. Create "steamcmd" folder in C:\DayZServer and place steamcmd.exe in this folder. Download it here https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip
3. open cmd
4. cd into steam cmd directory. Type "cd C:\DayZServer\steamcmd"
5. type "steamcmd.exe" to enetr steamcmd prompt
6. type "force_install_dir C:\DayZServer\steamcmd"
7. type "login USERNAME" (replace USERNAME with your steam username)
8. It will ask for password, go ahead an enter it. Will only need to do this once
9. type "app_update 223350 validate" to install server
10. After installation, type "exit" to exit steamcmd and return to windows cmd prompt
11. Place above modlist.txt with desired mods in format above into C:\DayServer folder

Note: I still recommend installing steam and subscribing to mods just to make sure they download to the workshop directory properly.

Create .bat file with the script in it below. I created two files. One to just handle restarts and mod updates and one that does the same but also updates/verifys the server files. The only change if you want to only update mods and do server reboots, you can comment out the following line (line 27 on my file):

echo app_update %DAYZ_APP_ID% validate >> "%SERVER_DIR%\steamcmd_script.txt"

@echo off
setlocal enabledelayedexpansion

:: SteamCMD configuration
set "STEAMCMD_PATH=C:\DayZServer\steamcmd"
:: Set the Steam login credentials
set "STEAM_USERNAME=your_steam_username"
:: Reminder: For security reasons, you might want to input the password during execution.
:: Set the server directory where mods will be installed or updated
set "SERVER_DIR=C:\DayZServer"
:: Path to the modlist file
set "MODLIST_PATH=C:\DayZServer\modlist.txt"
:: DayZ App ID
set "DAYZ_APP_ID=221100"
:: Steam Workshop content directory
set "WORKSHOP_CONTENT_DIR=C:\Program Files (x86)\Steam\steamapps\workshop\content\221100"
:: Set Keys Directory
set "KEYS_DIR=%SERVER_DIR%\keys"

:modFoldersAndContent
:: Update mods using SteamCMD
echo Updating DayZ Mods...
:: Initialize SteamCMD script with force_install_dir before login
echo force_install_dir "%SERVER_DIR%" > "%SERVER_DIR%\steamcmd_script.txt"
echo login %STEAM_USERNAME% >> "%SERVER_DIR%\steamcmd_script.txt"
:: Commented out the line below to not update day server files
echo app_update %DAYZ_APP_ID% validate >> "%SERVER_DIR%\steamcmd_script.txt"
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
echo workshop_download_item %DAYZ_APP_ID% %%a >> "%SERVER_DIR%\steamcmd_script.txt"
)
echo quit >> "%SERVER_DIR%\steamcmd_script.txt"

:: Execute the constructed SteamCMD command sequence from a script file
"%STEAMCMD_PATH%\steamcmd.exe" +runscript "%SERVER_DIR%\steamcmd_script.txt"

:: Move the downloaded content from Steam Workshop to the server folder
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
set "numericID=%%a"
set "modName=%%b"
set "modFolder=%%b" :: Corrected line: Use the mod name without extra '@'

:: Delete the old mod folder if it exists
if exist "%SERVER_DIR%\!modFolder!\" (
echo Deleting existing mod folder: !modFolder!
rmdir /S /Q "%SERVER_DIR%\!modFolder!" :: Deletes existing mod folder and all its contents
)

:: Create the mod folder if it doesn't exist
echo Creating mod folder: !modFolder!
mkdir "%SERVER_DIR%\!modFolder!"

:: Copy the downloaded content from Steam Workshop to the server folder
echo Copying contents for: %%b from !numericID!
xcopy "%WORKSHOP_CONTENT_DIR%\!numericID!\*" "%SERVER_DIR%\!modFolder!\" /E /I /Y
)

:: Initialize the mods string for server launch
set "MODS="

:: Construct the mod launch parameter from the modlist
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
set "modFolder=%%b" :: Corrected line: Use the mod name without extra '@'
set "MODS=!MODS!;!modFolder!"
)

:: Remove the leading semicolon from the mods string
set "MODS=!MODS:~1!"

echo Mods to be loaded: !MODS!

:: Section to copy keys from each mod's keys folder to the server's keys directory
:: Ensure the target keys directory exists
if not exist "%KEYS_DIR%" mkdir "%KEYS_DIR%"

:: Loop through each mod folder to copy keys
for /F "tokens=1* delims= " %%a in ('type "%MODLIST_PATH%"') do (
if exist "%SERVER_DIR%\%%b\keys\*" (
xcopy "%SERVER_DIR%\%%b\keys\*" "%KEYS_DIR%" /E /I /Y
)
)

:start
:: Server configurations
set "serverName=server_name"
set "serverLocation=C:\DayZServer"
set "profile=whatever_you_name_it"
set "serverPort=####"
set "steamQueryPort=####"
set "serverConfig=serverDZ.cfg"
set "serverCPU=# of cores"

title %serverName% batch
cd /d "%serverLocation%"
echo (%time%) %serverName% started.

:: Launch parameters
::output to ensure modlist is correct for start command
echo start "DayZ Server" /min DayZServer_x64.exe "-mod=%MODS%" -profiles=%profile% -config=%serverConfig% -port=%serverPort% -cpuCount=%serverCPU% -dologs -adminlog -netlog -freezecheck
start "DayZ Server" /min DayZServer_x64.exe "-mod=%MODS%" -profiles=%profile% -config=%serverConfig% -port=%serverPort% -cpuCount=%serverCPU% -dologs -adminlog -netlog -freezecheck

:: Wait before restarting server process
timeout /t 28880 /nobreak

:: Optionally kill DayZ Server process before restarting
taskkill /im DayZServer_x64.exe /F

goto modFoldersAndContent
< >
Affichage des commentaires 1 à 8 sur 8
Par page : 1530 50