From 43299f7ec13873eb92f9e2524eb1c6a22bae8d46 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Mon, 31 Jul 2023 00:25:17 +0100 Subject: [PATCH] refactor: simplify lockfile names and remove duplicate code - Renamed lockfiles from "${selfname}-started.lock" to "started.lock", "${selfname}-starting.lock" to "starting.lock", "${selfname}-stopping.lock" to "stopping.lock", and "${selfname}-update.lock" to "update.lock". - Removed duplicate code for removing stale lockfiles in fn_monitor_check_starting(), fn_monitor_check_stopping(), fn_monitor_check_backup(), fn_monitor_check_update(), update_factorio.sh, update_jediknight2.sh, update_minecraft.sh, update_minecraft_bedrock.sh, update_mta.sh, update_papermc.sh, update_ts3.sh, update_ut99.sh, and update_vintagestory.sh. - Updated references to the renamed lockfiles in the respective functions. --- lgsm/modules/command_debug.sh | 2 +- lgsm/modules/command_monitor.sh | 24 ++++++++++++------------ lgsm/modules/command_update.sh | 2 +- lgsm/modules/command_validate.sh | 2 +- lgsm/modules/core_steamcmd.sh | 2 +- lgsm/modules/update_factorio.sh | 2 +- lgsm/modules/update_jediknight2.sh | 2 +- lgsm/modules/update_minecraft.sh | 2 +- lgsm/modules/update_minecraft_bedrock.sh | 2 +- lgsm/modules/update_mta.sh | 2 +- lgsm/modules/update_papermc.sh | 2 +- lgsm/modules/update_ts3.sh | 2 +- lgsm/modules/update_ut99.sh | 2 +- lgsm/modules/update_vintagestory.sh | 2 +- 14 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lgsm/modules/command_debug.sh b/lgsm/modules/command_debug.sh index 5adab241a..c544e3e2a 100644 --- a/lgsm/modules/command_debug.sh +++ b/lgsm/modules/command_debug.sh @@ -98,7 +98,7 @@ fn_print_dots "Starting debug" fn_script_log_info "Starting debug" fn_print_ok_nl "Starting debug" -# Create lockfile. +# Create started lockfile. date '+%s' > "${lockdir:?}/${selfname}-started.lock" echo "${version}" >> "${lockdir}/${selfname}-started.lock" echo "${port}" >> "${lockdir}/${selfname}-started.lock" diff --git a/lgsm/modules/command_monitor.sh b/lgsm/modules/command_monitor.sh index 6e043c78b..1c1ad22ae 100644 --- a/lgsm/modules/command_monitor.sh +++ b/lgsm/modules/command_monitor.sh @@ -50,18 +50,18 @@ fn_monitor_check_debug() { fn_monitor_check_starting(){ # Remove stale lockfile. - if [ -f "${lockdir}/starting.lock" ]; then - if [ "$(find "${lockdir}/starting.lock" -mmin +5)" ]; then + if [ -f "${lockdir}/${selfname}-starting.lock" ]; then + if [ "$(find "${lockdir}/${selfname}-starting.lock" -mmin +5)" ]; then fn_print_dots "Checking start: " fn_print_checking_eol fn_print_warn "Checking start: Removing stale lockfile: " fn_print_warn_eol fn_script_log_warn "Checking start: Removing stale lockfile" - rm -f "${lockdir:?}/starting.lock" + rm -f "${lockdir:?}/${selfname}-starting.lock" fi fi - if [ -f "${lockdir}/starting.lock" ] && [[ "$(pgrep -fc -u "${USER}" "${selfname} start")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} s")" != "0" ]]; then + if [ -f "${lockdir}/${selfname}-starting.lock" ] && [[ "$(pgrep -fc -u "${USER}" "${selfname} start")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} s")" != "0" ]]; then fn_print_dots "Checking start: " fn_print_checking_eol fn_print_info "Checking start: LinuxGSM is starting: " @@ -73,18 +73,18 @@ fn_monitor_check_starting(){ fn_monitor_check_stopping(){ # Remove stale lockfile. - if [ -f "${lockdir}/stopping.lock" ]; then - if [ "$(find "${lockdir}/stopping.lock" -mmin +5)" ]; then + if [ -f "${lockdir}/${selfname}-stopping.lock" ]; then + if [ "$(find "${lockdir}/${selfname}-stopping.lock" -mmin +5)" ]; then fn_print_dots "Checking stop: " fn_print_checking_eol fn_print_warn "Checking stop: Removing stale lockfile: " fn_print_warn_eol fn_script_log_warn "Checking stop: Removing stale lockfile" - rm -f "${lockdir:?}/stopping.lock" + rm -f "${lockdir:?}/${selfname}-stopping.lock" fi fi - if [ -f "${lockdir}/stopping.lock" ] && [[ "$(pgrep -fc -u "${USER}" "${selfname} stop")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} s")" != "0" ]]; then + if [ -f "${lockdir}/${selfname}-stopping.lock" ] && [[ "$(pgrep -fc -u "${USER}" "${selfname} stop")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} s")" != "0" ]]; then fn_print_dots "Checking stop: " fn_print_checking_eol fn_print_info "Checking stop: LinuxGSM is stopping: " @@ -119,18 +119,18 @@ fn_monitor_check_backup() { fn_monitor_check_update() { # Remove stale lockfile. - if [ -f "${lockdir}/${selfname}-update.lock" ]; then - if [ "$(find "${lockdir}/${selfname}-update.lock" -mmin +15)" ]; then + if [ -f "${lockdir}/update.lock" ]; then + if [ "$(find "${lockdir}/update.lock" -mmin +15)" ]; then fn_print_dots "Checking update: " fn_print_checking_eol fn_print_warn "Checking update: Removing stale lockfile: " fn_print_warn_eol fn_script_log_warn "Checking update: Removing stale lockfile" - rm -f "${lockdir:?}/${selfname}-update.lock" + rm -f "${lockdir:?}/update.lock" fi fi - if [ -f "${lockdir}/${selfname}-update.lock" ] && [[ "$(pgrep -fc -u "${USER}" "${selfname} update")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} validate")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} v")" != "0" || "$(pgrep -fc force-update "${USER}" "${selfname} fu")" != "0" ]]; then + if [ -f "${lockdir}/update.lock" ] && [[ "$(pgrep -fc -u "${USER}" "${selfname} update")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} validate")" != "0" || "$(pgrep -fc -u "${USER}" "${selfname} v")" != "0" || "$(pgrep -fc force-update "${USER}" "${selfname} fu")" != "0" ]]; then fn_print_dots "Checking update: " fn_print_checking_eol fn_print_info_nl "Checking update: LinuxGSM is updating: " diff --git a/lgsm/modules/command_update.sh b/lgsm/modules/command_update.sh index 3fda040f0..62221d5e6 100644 --- a/lgsm/modules/command_update.sh +++ b/lgsm/modules/command_update.sh @@ -38,6 +38,6 @@ else fi # remove update lockfile. -rm -f "${lockdir:?}/${selfname}-update.lock" +rm -f "${lockdir:?}/update.lock" core_exit.sh diff --git a/lgsm/modules/command_validate.sh b/lgsm/modules/command_validate.sh index 0de9ded9a..ecd2ed141 100644 --- a/lgsm/modules/command_validate.sh +++ b/lgsm/modules/command_validate.sh @@ -47,6 +47,6 @@ else fi # remove update lockfile -rm -f "${lockdir:?}/${selfname}-update.lock" +rm -f "${lockdir:?}/update.lock" core_exit.sh diff --git a/lgsm/modules/core_steamcmd.sh b/lgsm/modules/core_steamcmd.sh index 064823683..54de61b7c 100644 --- a/lgsm/modules/core_steamcmd.sh +++ b/lgsm/modules/core_steamcmd.sh @@ -207,7 +207,7 @@ fn_update_steamcmd_compare() { # Update has been found or force update. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then # Create update lockfile. - date '+%s' > "${lockdir:?}/${selfname}-update.lock" + date '+%s' > "${lockdir:?}/update.lock" fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available" diff --git a/lgsm/modules/update_factorio.sh b/lgsm/modules/update_factorio.sh index df1067fc1..f7fb06c7d 100644 --- a/lgsm/modules/update_factorio.sh +++ b/lgsm/modules/update_factorio.sh @@ -67,7 +67,7 @@ fn_update_compare() { # Update has been found or force update. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then # Create update lockfile. - date '+%s' > "${lockdir:?}/${selfname}-update.lock" + date '+%s' > "${lockdir:?}/update.lock" fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available" diff --git a/lgsm/modules/update_jediknight2.sh b/lgsm/modules/update_jediknight2.sh index a2af2fc7b..e67b0c02b 100644 --- a/lgsm/modules/update_jediknight2.sh +++ b/lgsm/modules/update_jediknight2.sh @@ -64,7 +64,7 @@ fn_update_compare() { # Update has been found or force update. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then # Create update lockfile. - date '+%s' > "${lockdir:?}/${selfname}-update.lock" + date '+%s' > "${lockdir:?}/update.lock" fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available" diff --git a/lgsm/modules/update_minecraft.sh b/lgsm/modules/update_minecraft.sh index 8efc1e8f7..cfdf7e057 100644 --- a/lgsm/modules/update_minecraft.sh +++ b/lgsm/modules/update_minecraft.sh @@ -78,7 +78,7 @@ fn_update_compare() { # Update has been found or force update. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then # Create update lockfile. - date '+%s' > "${lockdir:?}/${selfname}-update.lock" + date '+%s' > "${lockdir:?}/update.lock" fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available" diff --git a/lgsm/modules/update_minecraft_bedrock.sh b/lgsm/modules/update_minecraft_bedrock.sh index 768771926..92bffca31 100644 --- a/lgsm/modules/update_minecraft_bedrock.sh +++ b/lgsm/modules/update_minecraft_bedrock.sh @@ -83,7 +83,7 @@ fn_update_compare() { # Update has been found or force update. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then # Create update lockfile. - date '+%s' > "${lockdir:?}/${selfname}-update.lock" + date '+%s' > "${lockdir:?}/update.lock" fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available" diff --git a/lgsm/modules/update_mta.sh b/lgsm/modules/update_mta.sh index c25e5242e..eab77c748 100644 --- a/lgsm/modules/update_mta.sh +++ b/lgsm/modules/update_mta.sh @@ -62,7 +62,7 @@ fn_update_compare() { # Update has been found or force update. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then # Create update lockfile. - date '+%s' > "${lockdir:?}/${selfname}-update.lock" + date '+%s' > "${lockdir:?}/update.lock" if [ "${forceupdate}" == "1" ]; then # forceupdate bypasses checks, useful for small build changes mtaupdatestatus="forced" diff --git a/lgsm/modules/update_papermc.sh b/lgsm/modules/update_papermc.sh index bce3aaedf..2438c2d86 100644 --- a/lgsm/modules/update_papermc.sh +++ b/lgsm/modules/update_papermc.sh @@ -88,7 +88,7 @@ fn_update_compare() { # Update has been found or force update. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then # Create update lockfile. - date '+%s' > "${lockdir:?}/${selfname}-update.lock" + date '+%s' > "${lockdir:?}/update.lock" fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available" diff --git a/lgsm/modules/update_ts3.sh b/lgsm/modules/update_ts3.sh index a47ba1f74..b031d2b34 100644 --- a/lgsm/modules/update_ts3.sh +++ b/lgsm/modules/update_ts3.sh @@ -71,7 +71,7 @@ fn_update_compare() { # Update has been found or force update. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then # Create update lockfile. - date '+%s' > "${lockdir:?}/${selfname}-update.lock" + date '+%s' > "${lockdir:?}/update.lock" fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available" diff --git a/lgsm/modules/update_ut99.sh b/lgsm/modules/update_ut99.sh index c45ae990f..1ff84a060 100644 --- a/lgsm/modules/update_ut99.sh +++ b/lgsm/modules/update_ut99.sh @@ -65,7 +65,7 @@ fn_update_compare() { # Update has been found or force update. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then # Create update lockfile. - date '+%s' > "${lockdir:?}/${selfname}-update.lock" + date '+%s' > "${lockdir:?}/update.lock" fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available" diff --git a/lgsm/modules/update_vintagestory.sh b/lgsm/modules/update_vintagestory.sh index c87783f36..01c1364a0 100644 --- a/lgsm/modules/update_vintagestory.sh +++ b/lgsm/modules/update_vintagestory.sh @@ -72,7 +72,7 @@ fn_update_compare() { # Update has been found or force update. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then # Create update lockfile. - date '+%s' > "${lockdir:?}/${selfname}-update.lock" + date '+%s' > "${lockdir:?}/update.lock" fn_print_ok_nl "Checking for update: ${remotelocation}" echo -en "\n" echo -e "Update available"