Browse Source

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.
pull/4296/head
Daniel Gibbs 2 years ago
parent
commit
43299f7ec1
  1. 2
      lgsm/modules/command_debug.sh
  2. 24
      lgsm/modules/command_monitor.sh
  3. 2
      lgsm/modules/command_update.sh
  4. 2
      lgsm/modules/command_validate.sh
  5. 2
      lgsm/modules/core_steamcmd.sh
  6. 2
      lgsm/modules/update_factorio.sh
  7. 2
      lgsm/modules/update_jediknight2.sh
  8. 2
      lgsm/modules/update_minecraft.sh
  9. 2
      lgsm/modules/update_minecraft_bedrock.sh
  10. 2
      lgsm/modules/update_mta.sh
  11. 2
      lgsm/modules/update_papermc.sh
  12. 2
      lgsm/modules/update_ts3.sh
  13. 2
      lgsm/modules/update_ut99.sh
  14. 2
      lgsm/modules/update_vintagestory.sh

2
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"

24
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: "

2
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

2
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

2
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"

2
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"

2
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"

2
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"

2
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"

2
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"

2
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"

2
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"

2
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"

2
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"

Loading…
Cancel
Save