lockserver

This commit is contained in:
2023-11-25 01:05:22 -06:00
parent 4bc6f900b3
commit 4a718e39e4
4 changed files with 145 additions and 64 deletions

View File

@@ -7,58 +7,54 @@
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# General Settings
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
export DAYZ_FILES=/mnt/dayz
export STOCK_SERVER_DATA="$DAYZ_FILES/stock/DayZServer"
export MAIN="/mnt/c/DAYZ"
export SERVERS="$MAIN/servers"
export CACHE="$MAIN/cache"
export MOD_CACHE="$CACHE/mods"
export RESTART_INTERVAL=$((60 * 60 * 4 + 3))
# export DAYZ_FILES=/mnt/dayz
# export STOCK_SERVER_DATA="$DAYZ_FILES/stock/DayZServer"
# export MAIN="/mnt/c/DAYZ"
# export SERVERS="$MAIN/servers"
# export CACHE="$MAIN/cache"
# export MOD_CACHE="$CACHE/mods"
# export RESTART_INTERVAL=$((60 * 60 * 4 + 3))
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# Helper functions
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
alias do_sync='rsync -rltDh --delete --partial'
msg() {
>&2 printf '[*] %s ...\n' "$*"
}
warn() {
>&2 printf '\n\n<<<< WARNING: %s >>>>>\n\n' "$*"
}
die() {
msg "$*"
exit 1
}
debug() {
if [ "$DEBUG" ] ; then
>&2 printf ' DEBUG: %s\n' "$*"
fi
}
# alias do_sync='rsync -rltDh --delete --partial'
# msg() {
# >&2 printf '[*] %s ...\n' "$*"
# }
# warn() {
# >&2 printf '\n\n<<<< WARNING: %s >>>>>\n\n' "$*"
# }
# die() {
# msg "$*"
# exit 1
# }
# debug() {
# if [ "$DEBUG" ] ; then
# >&2 printf ' DEBUG: %s\n' "$*"
# fi
# }
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# Checks
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
check() {
mkdir -p "$DAYZ_FILES"
# check() {
# mkdir -p "$DAYZ_FILES"
if ! mount | grep -i "$DAYZ_FILES" >/dev/null ; then
msg "$DAYZ_FILES is not mounted!"
echo "hint: mount -t drvfs //truenas.home.weaver/dayz $DAYZ_FILES"
exit 1
fi
# if ! mount | grep -i "$DAYZ_FILES" >/dev/null ; then
# msg "$DAYZ_FILES is not mounted!"
# echo "hint: mount -t drvfs //truenas.home.weaver/dayz $DAYZ_FILES"
# exit 1
# fi
if [ ! -d "$MAIN" ] ; then
die "$MAIN does not exist"
fi
# if [ ! -d "$MAIN" ] ; then
# die "$MAIN does not exist"
# fi
if [ ! -d "$STOCK_SERVER_DATA" ] ; then
die "$STOCK_SERVER_DATA does not exist"
fi
}
# if [ ! -d "$STOCK_SERVER_DATA" ] ; then
# die "$STOCK_SERVER_DATA does not exist"
# fi
# }
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# Environment Setup

View File

@@ -48,6 +48,11 @@ die() {
errmsg "$*"
exit 1
}
debug() {
if [ "$DEBUG" ] ; then
>&2 printf '>>>>>>>>>DEBUG: %s\n' "$*"
fi
}
isempty() {
for arg in "$@" ; do
# exit in error if file

View File

@@ -29,6 +29,7 @@ export LOCAL_STOCK="$HOME/stock"
export LOCAL_STOCK_GAME="$LOCAL_STOCK/DayZ"
export LOCAL_STOCK_SERVER="$LOCAL_STOCK/DayZServer"
export LOCAL_MODS="$HOME/mods"
export LOCKFILE="$REMOTE_DIR/lockfile"
# ===================================================
# 03. Mount network drive
@@ -44,6 +45,7 @@ fi
# ===================================================
# 04. Checks
# ===================================================
check() {
mkdir -p "$LOCAL_STOCK_GAME" "$LOCAL_STOCK_SERVER" "$LOCAL_MODS"
if [ "$USER" != "$STEAMCMD_USER" ] ; then
@@ -62,6 +64,13 @@ if [ ! -d "$REMOTE_MAPS" ] ; then
die "Could not find remote maps at: $REMOTE_MAPS"
fi
if islocked_remote_server ; then
die "Remote server already locked?"
fi
msg "Health checks passed successfully."
}
# ===================================================
# 05. Begin functions
# ===================================================
@@ -259,7 +268,32 @@ update_stock_maps() {
# --------------------------------------------------------------------------------------------------------------------
}
islocked_remote_server() {
if [ -e "$LOCKFILE" ] ; then
msg "Server is not currently locked!"
return 0
else
return 1
fi
}
lock_remote_server() {
msg "Locking remote server."
if ! echo 'locked' | tee "$LOCKFILE" ; then
die "Could not create: $LOCKFILE"
fi
}
unlock_remote_server() {
msg "Unlocking remote server."
rm -f "$LOCKFILE" || die "Could not remove: $LOCKFILE"
}
main() {
check || die "Failed to pass health checks"
lock_remote_server
update_server
update_game
update_stock_maps
@@ -271,6 +305,8 @@ main() {
# rm -rf "$HOME/.steam/debian-installation/steamapps/workshop/downloads"
# mkdir -p "$HOME/.steam/debian-installation/steamapps/workshop/downloads"
done
unlock_remote_server
}
main "$@"
main "$@" || exit 1

View File

@@ -1,9 +1,17 @@
#!/usr/bin/env bash
#
# shellcheck disable=2043
# 01. "should check code directly not $?"
# shellcheck disable=2181
#
# 02. "can't follow . import"
# shellcheck disable=1090
#
# -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
##################### CHANGE ME #################################
export SERVER_NAME="XXXXXXXXXX"
##################### CHANGE ME #################################
# ===================================================
# 01. Attempt to load global DayZ values
# ===================================================
@@ -20,9 +28,45 @@ fi
# ===================================================
# 02. Local script variables
# ===================================================
#
#
# Local server file hierarchy:
#
# c:/DAYZ
# ^--/servers
# ^--/cache
#
export MAIN="/mnt/c/DAYZ"
export CACHE="$MAIN/cache"
export MOD_CACHE="$CACHE/mods"
export SERVERS="$MAIN/servers"
export SERVER_HOME="$SERVERS/$SERVER_NAME"
export RESTART_INTERVAL=$((60 * 60 * 4 + 3))
main() {
:
# ===================================================
# 03. init and checks
# ===================================================
check() {
if [ ! -d "$MAIN" ] ; then
die "dir: $MAIN does not exist"
fi
if [ ! -d "$SERVER_HOME" ] ; then
die "dir: $SERVER_HOME does not exist"
fi
msg "Health checks completed successfully."
}
main "$@"
init() {
check || die "Failed check()"
mkdir -p "$CACHE" "$MOD_CACHE"
msg "Completed intialization. Using server restart time of $RESTART_INTERVAL seconds."
}
# ===================================================
main() {
check || die "Failed check()"
}
main "$@" || exit 1