Merge branch 'master' of ssh://gitea.local.wvr.sh:2221/mitch/dayz-servers

This commit is contained in:
2023-11-26 09:23:36 -06:00
2 changed files with 47 additions and 76 deletions

View File

@@ -149,9 +149,20 @@ lock_remote_server() {
die "Could not create: $REMOTE_SERVER_LOCKFILE" die "Could not create: $REMOTE_SERVER_LOCKFILE"
fi fi
} }
unlock_remote_server() { unlock_remote_server() {
msg "Unlocking remote server." msg "Unlocking remote server."
rm -f "$REMOTE_SERVER_LOCKFILE" || die "Could not remove: $REMOTE_SERVER_LOCKFILE" rm -f "$REMOTE_SERVER_LOCKFILE" || die "Could not remove: $REMOTE_SERVER_LOCKFILE"
} }
wait_until_remote_server_unlocked() {
# wait until dayz-modserver lockfile is released on the NAS
if islocked_remote_server ; then
msg "Remote file server is currently locked"
msg "Sleeping until is no longer locked..."
while islocked_remote_server ; do
echo "Sleeping..."
sleep 10
done
msg "Server unlocked! Continuing..."
fi
}
# ===================================================================================== # =====================================================================================

View File

@@ -49,7 +49,9 @@ export SERVERS="$LOCAL_DAYZ_FILES/servers"
################################# export RESTART_INTERVAL=$((60 * 60 * 4)) ################################# export RESTART_INTERVAL=$((60 * 60 * 4))
# (10 minutes) # (10 minutes)
export RESTART_INTERVAL=$((10 * 60)) # export RESTART_INTERVAL=$((10 * 60))
export RESTART_INTERVAL=$((1 * 60))
# =================================================== # ===================================================
# 03. Mount network drive # 03. Mount network drive
@@ -78,7 +80,7 @@ check() {
init_server() { init_server() {
mkdir -p "$SERVER_HOME" "$CACHE" "$MOD_CACHE" "$STOCK_SERVER_CACHE" "$LOCAL_DAYZ_FILES/stock/maps/$MAP_FOLDER_NAME" mkdir -p "$SERVER_HOME" "$CACHE" "$MOD_CACHE" "$STOCK_SERVER_CACHE" "$LOCAL_DAYZ_FILES/stock/maps/$MAP_FOLDER_NAME"
:>"$SERVER_HOME/.modstring" :>"$SERVER_HOME/modstring"
check || die "Failed check()" check || die "Failed check()"
@@ -99,52 +101,26 @@ load_stock_map_data() {
refresh_local_cache() { refresh_local_cache() {
msg "Refreshing local stock server cache" msg "Refreshing local stock server cache"
if ! islocked_remote_server ; then wait_until_remote_server_unlocked
do_sync "$REMOTE_STOCK_SERVER"/ "$STOCK_SERVER_CACHE" || die "Failed to copy remote stock server data to local cache" do_sync "$REMOTE_STOCK_SERVER"/ "$STOCK_SERVER_CACHE" || \
else die "Failed to copy remote stock server data to local cache"
msg "Remote server is locked, sleeping..."
while islocked_remote_server ; do
sleep 15
echo 'Sleeping...'
done
do_sync "$REMOTE_STOCK_SERVER"/ "$STOCK_SERVER_CACHE" || die "Failed to copy remote stock server data to local cache"
fi
msg "Sucessfully copied stock server data into local cache" msg "Sucessfully copied stock server data into local cache"
# ------------------------------------- # -------------------------------------
msg "Refreshing local map data cache for: $MAP_FOLDER_NAME" msg "Refreshing local map data cache for: $MAP_FOLDER_NAME"
if ! islocked_remote_server ; then wait_until_remote_server_unlocked
do_sync "$REMOTE_MAPS/$MAP_FOLDER_NAME"/ "$LOCAL_DAYZ_FILES/stock/maps/$MAP_FOLDER_NAME" || \ do_sync "$REMOTE_MAPS/$MAP_FOLDER_NAME"/ "$LOCAL_DAYZ_FILES/stock/maps/$MAP_FOLDER_NAME" || \
die "Failed to copy remote stock map data for: $MAP_FOLDER_NAME" die "Failed to copy remote stock map data for: $MAP_FOLDER_NAME"
else
msg "Remote server is locked, sleeping..."
while islocked_remote_server ; do
sleep 15
echo 'Sleeping...'
done
do_sync "$REMOTE_MAPS/$MAP_FOLDER_NAME"/ "$LOCAL_DAYZ_FILES/stock/maps/$MAP_FOLDER_NAME" || \
die "Failed to copy remote stock map data for: $MAP_FOLDER_NAME"
fi
msg "Successfully copied stock map data for: $MAP_FOLDER_NAME" msg "Successfully copied stock map data for: $MAP_FOLDER_NAME"
# ------------------------------------- # -------------------------------------
msg "Refreshing local mods cache" msg "Refreshing local mods cache"
if ! islocked_remote_server ; then wait_until_remote_server_unlocked
do_sync "$REMOTE_MODS"/ "$MOD_CACHE" || die "Failed to copy remote mods to local cache" do_sync "$REMOTE_MODS"/ "$MOD_CACHE" || \
else die "Failed to copy remote mods to local cache"
msg "Remote server is locked, sleeping..."
while islocked_remote_server ; do
sleep 15
echo 'Sleeping...'
done
do_sync "$REMOTE_MODS"/ "$MOD_CACHE" || die "Failed to copy remote mods to local cache"
fi
msg "Successfully copied remote mods into local cache" msg "Successfully copied remote mods into local cache"
} }
setup_environment() { setup_environment() {
msg "Setting up environment"
msg "Copying stock server data from local cache into $SERVER_HOME" msg "Copying stock server data from local cache into $SERVER_HOME"
# list of all stock server folders # list of all stock server folders
for folder in addons battleye bliss docs dta keys ; do for folder in addons battleye bliss docs dta keys ; do
@@ -164,12 +140,15 @@ setup_environment() {
do_sync "$MOD_CACHE/$MAP_FOLDER_NAME"/ "$SERVER_HOME/mods" || die "Failed to copy mods to $SERVER_HOME" do_sync "$MOD_CACHE/$MAP_FOLDER_NAME"/ "$SERVER_HOME/mods" || die "Failed to copy mods to $SERVER_HOME"
msg "Copying DZSA executable" msg "Copying DZSA executable"
do_sync "$REMOTE_DIR/res/software/DZSALModServer.exe" "$SERVER_HOME"/ || die "Failed to copy DZSALModServer.exe" wait_until_remote_server_unlocked
do_sync "$REMOTE_DIR/res/software/DZSALModServer.exe" "$SERVER_HOME"/ || \
die "Failed to copy DZSALModServer.exe"
} }
# finds list of mods to load and stores them in .modstring file # finds list of mods to load and stores them in modstring file
# to be used as parameters to the server # to be used as parameters to the server
load_mods() { load_mods() {
msg "Loading mods"
if [ ! -f "$MOD_CACHE/$MAP_FOLDER_NAME/mods.txt" ] ; then if [ ! -f "$MOD_CACHE/$MAP_FOLDER_NAME/mods.txt" ] ; then
die "mods.txt list for $MAP_FOLDER_NAME is missing" die "mods.txt list for $MAP_FOLDER_NAME is missing"
fi fi
@@ -208,11 +187,8 @@ load_mods() {
# trim the initial leading ';' # trim the initial leading ';'
_modstring=${_modstring#;} _modstring=${_modstring#;}
printf '%s\n' "$_modstring" > .modstring printf '%s\n' "$_modstring" > modstring
unset _modstring msg "Mods successfully loaded."
msg "Mods successfully loaded. Using modstring:"
printf '"%s"\n' "$(cat .modstring)"
} }
# =================================================== # ===================================================
@@ -220,43 +196,33 @@ load_mods() {
# =================================================== # ===================================================
start_server() { start_server() {
check || die "Failed check()" check || die "Failed check()"
# wait until dayz-modserver lockfile is released on the NAS
if islocked_remote_server ; then
msg "Remote file server is currently locked"
msg "Sleeping until is no longer locked..."
while islocked_remote_server ; do
echo "Sleeping..."
sleep 10
done
msg "Server unlocked! Continuing..."
fi
cd "$SERVER_HOME" || die "Could not cd to '$SERVER_HOME'" cd "$SERVER_HOME" || die "Could not cd to '$SERVER_HOME'"
msg "Setting up environment" wait_until_remote_server_unlocked
setup_environment || die "Could not set up environment." setup_environment || die "Could not set up environment."
msg "Loading mods"
load_mods || die "Could not load mods" load_mods || die "Could not load mods"
mod_string=$(cat .modstring)
# ===================================================================================== # =====================================================================================
# creating temp.bat here to avoid the arg max char limit of windows cmd.exe # creating temp.bat here to avoid the arg max char limit of windows cmd.exe
PROCESS_NAME="SERVER: $SERVER_NAME"
cat > temp.bat <<EOF cat > temp.bat <<EOF
:start :start
start "$SERVER_NAME" /min DZSALModServer.exe -config=serverDZ.cfg -port="$SERVER_PORT" -profiles=Profilesfolder -mod="$mod_string" -cpuCount="$SERVER_CPU" -dologs -adminlog -netlog -freezecheck start "$PROCESS_NAME" ^
/min DZSALModServer.exe ^
-config=serverDZ.cfg ^
-port="$SERVER_PORT" ^
-profiles=Profilesfolder ^
-mod="$(cat modstring)" ^
-cpuCount="$SERVER_CPU" ^
-dologs -adminlog -netlog -freezecheck
EOF EOF
# ===================================================================================== # =====================================================================================
# start the server # start the server
cmd.exe /C temp.bat cmd.exe /C temp.bat
rm -f temp.bat modstring 2>/dev/null ||:
echo '====================================' msg '%s - Server started.\n' "$(date)"
printf '%s - Server started.\n' "$(date)"
echo '===================================='
printf '\n**** Sleeping for: %s *****\n\n' "$RESTART_INTERVAL"
count=0 count=0
while [ "$count" -lt "$RESTART_INTERVAL" ] ; do while [ "$count" -lt "$RESTART_INTERVAL" ] ; do
@@ -265,17 +231,12 @@ EOF
msg "TIME LEFT BEFORE RESTART: $(( (RESTART_INTERVAL - count) / 60 )) minutes" msg "TIME LEFT BEFORE RESTART: $(( (RESTART_INTERVAL - count) / 60 )) minutes"
done done
echo "===========================" msg "Time up - Killing server"
cmd.exe /C taskkill /FI "WINDOWTITLE eq $PROCESS_NAME"
msg "Time up"
msg "Killing server"
cmd.exe /C taskkill /im DayZServer_x64.exe /F
rm -f temp.bat 2>/dev/null ||:
msg "Sleeping 10 seconds to settle" msg "Sleeping 10 seconds to settle"
sleep 10 sleep 10
msg "SERVER IS RESTARTING" msg "SERVER IS RESTARTING"
} }
# =================================================== # ===================================================
@@ -293,8 +254,7 @@ main() {
# this must be here and not up top as we must load it from the SERVER.ENV # this must be here and not up top as we must load it from the SERVER.ENV
export SERVER_HOME="$SERVERS/$SERVER_NAME" export SERVER_HOME="$SERVERS/$SERVER_NAME"
# create directories in $SERVER_HOME # create directories in $SERVER_HOME, blank the modstring
# blank the modstring
init_server init_server
if [ -e ./serverDZ.cfg ] ; then if [ -e ./serverDZ.cfg ] ; then