Browse Source

refactor: remove redundant code and improve socket name generation

The commit refactors the code in `command_start.sh` and `linuxgsm.sh` to remove redundant code related to generating a unique tmux socket name. The code now creates a uid file if it doesn't exist, stops the running server, generates a uid using the current timestamp, and updates the socketname accordingly. This change improves the efficiency and reliability of socket name generation.
pull/4304/head
Daniel Gibbs 2 years ago
parent
commit
0e5a9947f4
  1. 12
      lgsm/modules/command_start.sh
  2. 13
      linuxgsm.sh

12
lgsm/modules/command_start.sh

@ -48,16 +48,6 @@ fn_start_tmux() {
fn_reload_startparameters
# Create uid to ensure unique tmux socket name.
if [ ! -f "${datadir}/${selfname}.uid" ]; then
# stop running server (if running) to prevent lingering tmux sessions.
exitbypass=1
command_stop.sh
uid=$(date '+%s' | sha1sum | head -c 8)
echo "${uid}" > "${datadir}/${selfname}.uid"
socketname="${sessionname}-$(cat "${datadir}/${selfname}.uid")"
fi
if [ "${shortname}" == "av" ]; then
cd "${systemdir}" || exit
else
@ -181,7 +171,7 @@ fn_start_tmux() {
check.sh
# If user ran the start command monitor will become enabled.
if [ "${firstcommandname}" == "START" ]||[ "${firstcommandname}" == "RESTART" ]; then
if [ "${firstcommandname}" == "START" ] || [ "${firstcommandname}" == "RESTART" ]; then
date '+%s' > "${lockdir:?}/${selfname}-monitoring.lock"
fi

13
linuxgsm.sh

@ -36,7 +36,7 @@ tmpdir="${lgsmdir}/tmp"
datadir="${lgsmdir}/data"
lockdir="${lgsmdir}/lock"
sessionname="${selfname}"
[ -f "${datadir}/${selfname}.uid" ] && socketname="${sessionname}-$(cat "${datadir}/${selfname}.uid")" || socketname="${sessionname}"
socketname="${sessionname}-$(cat "${datadir}/${selfname}.uid")"
serverlist="${datadir}/serverlist.csv"
serverlistmenu="${datadir}/serverlistmenu.csv"
[ -n "${LGSM_CONFIG}" ] && configdir="${LGSM_CONFIG}" || configdir="${lgsmdir}/config-lgsm"
@ -413,6 +413,17 @@ else
fi
fi
fi
# Create uid to ensure unique tmux socket name.
if [ ! -f "${datadir}/${selfname}.uid" ]; then
# stop running server (if running) to prevent lingering tmux sessions.
exitbypass=1
command_stop.sh
uid=$(date '+%s' | sha1sum | head -c 8)
echo "${uid}" > "${datadir}/${selfname}.uid"
socketname="${sessionname}-$(cat "${datadir}/${selfname}.uid")"
fi
# Load the IP details before the first config is loaded.
check_ip.sh
# Configs have to be loaded twice to allow start startparameters to pick up all vars

Loading…
Cancel
Save