From edb8dc3a0bc97baaa54f950d95550456e7458b74 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Mon, 4 Sep 2023 21:03:07 +0100 Subject: [PATCH] refactor: remove duplicate code for creating unique tmux socket name The code changes in `command_start.sh` and `linuxgsm.sh` refactor the creation of a unique tmux socket name. The duplicate code in `linuxgsm.sh` has been removed, resulting in cleaner and more efficient code. --- lgsm/modules/command_start.sh | 13 +++++++++++++ linuxgsm.sh | 9 --------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lgsm/modules/command_start.sh b/lgsm/modules/command_start.sh index cabccac47..963815b1b 100644 --- a/lgsm/modules/command_start.sh +++ b/lgsm/modules/command_start.sh @@ -48,6 +48,19 @@ fn_start_tmux() { fn_reload_startparameters + # Create uid to ensure unique tmux socket name. + if [ ! -f "${datadir}/${selfname}.uid" ]; then + check_status.sh + if [ "${status}" != "0" ]; then + # stop running server (if running) to prevent lingering tmux sessions. + exitbypass=1 + command_stop.sh + fi + 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 diff --git a/linuxgsm.sh b/linuxgsm.sh index 76a470a63..19fdf1a54 100755 --- a/linuxgsm.sh +++ b/linuxgsm.sh @@ -414,15 +414,6 @@ else 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 - 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