From 4c6b1daf74bdc2d6051fb9f5f96753425c7687bc Mon Sep 17 00:00:00 2001 From: aguy tech Date: Sat, 21 Nov 2020 23:26:01 +0100 Subject: [PATCH 1/5] Linux: Modifications to allow session restoration --- scripts/handle_tmux_automatic_start/systemd_enable.sh | 2 +- scripts/variables.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/handle_tmux_automatic_start/systemd_enable.sh b/scripts/handle_tmux_automatic_start/systemd_enable.sh index d37c889..c160560 100755 --- a/scripts/handle_tmux_automatic_start/systemd_enable.sh +++ b/scripts/handle_tmux_automatic_start/systemd_enable.sh @@ -19,7 +19,7 @@ template() { [Service] Type=forking Environment=DISPLAY=:0 - ExecStart=/usr/bin/tmux ${systemd_tmux_server_start_cmd} + ExecStart="${systemd_tmux_server_start_cmd_default}" ExecStop=${HOME}/.tmux/plugins/tmux-resurrect/scripts/save.sh ExecStop=/usr/bin/tmux kill-server diff --git a/scripts/variables.sh b/scripts/variables.sh index 8d0a057..9b9823e 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -36,5 +36,6 @@ status_wrap_string="\#{value}" systemd_service_name="tmux.service" systemd_unit_file_path="$HOME/.config/systemd/user/${systemd_service_name}" +tmux_server_session_temporary="tmux-continuum-tmp" systemd_tmux_server_start_cmd_option="@continuum-systemd-start-cmd" -systemd_tmux_server_start_cmd_default="new-session -d" +systemd_tmux_server_start_cmd_default="/usr/bin/tmux ${systemd_tmux_server_start_cmd} -s ${tmux_server_session_temporary} && /usr/bin/tmux kill-session -t ${tmux_server_session_temporary}" From 3007c867cfb5720fa5ca12a434d076b8f2894da7 Mon Sep 17 00:00:00 2001 From: aguy tech Date: Mon, 23 Nov 2020 09:12:35 +0100 Subject: [PATCH 2/5] Corrects an error && Gives a better integration --- scripts/handle_tmux_automatic_start/systemd_enable.sh | 8 ++++++-- scripts/variables.sh | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/handle_tmux_automatic_start/systemd_enable.sh b/scripts/handle_tmux_automatic_start/systemd_enable.sh index c160560..0b5ff72 100755 --- a/scripts/handle_tmux_automatic_start/systemd_enable.sh +++ b/scripts/handle_tmux_automatic_start/systemd_enable.sh @@ -19,7 +19,7 @@ template() { [Service] Type=forking Environment=DISPLAY=:0 - ExecStart="${systemd_tmux_server_start_cmd_default}" + ExecStart=${systemd_tmux_server_start_cmd} ExecStop=${HOME}/.tmux/plugins/tmux-resurrect/scripts/save.sh ExecStop=/usr/bin/tmux kill-server @@ -46,7 +46,11 @@ enable_tmux_unit_on_boot() { main() { local options="$(get_tmux_option "$auto_start_config_option" "${auto_start_config_default}")" - local systemd_tmux_server_start_cmd="$(get_tmux_option "${systemd_tmux_server_start_cmd_option}" "${systemd_tmux_server_start_cmd_default}" )" + # start tmux with a temporary session + local systemd_tmux_server_start_cmd_default="/usr/bin/tmux $(get_tmux_option "${systemd_tmux_server_start_cmd_option}" "${systemd_tmux_server_start_cmd_default}" ) -s ${tmux_server_session_temporary}" + # adds sleep to give tmux some time to finish dettached subprocess "fetch_and_run_tmux_resurrect_restore_script" + # and kills tmux temporary session + local systemd_tmux_server_start_cmd="${systemd_tmux_server_start_cmd_default} && sleep 2 && /usr/bin/tmux kill-session -t ${tmux_server_session_temporary}" local tmux_start_script_path="${CURRENT_DIR}/linux_start_tmux.sh" local systemd_unit_file=$(template "${tmux_start_script_path}" "${options}") mkdir -p "$(dirname ${systemd_unit_file_path})" diff --git a/scripts/variables.sh b/scripts/variables.sh index 9b9823e..33d98ed 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -38,4 +38,4 @@ systemd_unit_file_path="$HOME/.config/systemd/user/${systemd_service_name}" tmux_server_session_temporary="tmux-continuum-tmp" systemd_tmux_server_start_cmd_option="@continuum-systemd-start-cmd" -systemd_tmux_server_start_cmd_default="/usr/bin/tmux ${systemd_tmux_server_start_cmd} -s ${tmux_server_session_temporary} && /usr/bin/tmux kill-session -t ${tmux_server_session_temporary}" +systemd_tmux_server_start_cmd_default="new-session -d" From 400724bad0cc070a89a23f9d04e0d93bc9212b26 Mon Sep 17 00:00:00 2001 From: aguy tech Date: Tue, 24 Nov 2020 00:12:13 +0100 Subject: [PATCH 3/5] global modifications to properly restore saved sessions --- scripts/continuum_start.sh | 38 +++++++++++++++++++ .../systemd_enable.sh | 14 +++---- scripts/variables.sh | 2 +- 3 files changed, 44 insertions(+), 10 deletions(-) create mode 100755 scripts/continuum_start.sh diff --git a/scripts/continuum_start.sh b/scripts/continuum_start.sh new file mode 100755 index 0000000..b7fad10 --- /dev/null +++ b/scripts/continuum_start.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( dirname "$0" )" + +echo -e "\n$(date +%T) IN" >> /tmp/continuum + +source "$CURRENT_DIR/helpers.sh" +source "$CURRENT_DIR/variables.sh" + +start_tmux() { + local systemd_tmux_server_start_cmd="$(get_tmux_option "${systemd_tmux_server_start_cmd_option}" "${systemd_tmux_server_start_cmd_default}" )" + /usr/bin/tmux ${systemd_tmux_server_start_cmd} +} + +clean_session() { + local sessions_count="$(tmux list-sessions 2>/dev/null | wc -l)" + + if /usr/bin/tmux has-session -t "${tmux_server_session_temporary}"; then + # add a new session to preserve server daemon + [ "${sessions_count}" = 1 ] && tmux new-session -d && \ + echo "$(date +%T) add session" >> /tmp/continuum + + # kill session + echo "$(date +%T) kill session" >> /tmp/continuum + /usr/bin/tmux kill-session -t "${tmux_server_session_temporary}" + fi +} + +main() { + start_tmux + + # wait detached process of session restoration : start_auto_restore_in_background() + # with a sleep 1 inside fetch_and_run_tmux_resurrect_restore_script() + #sleep 1 + + clean_session +} +main \ No newline at end of file diff --git a/scripts/handle_tmux_automatic_start/systemd_enable.sh b/scripts/handle_tmux_automatic_start/systemd_enable.sh index 0b5ff72..390f44b 100755 --- a/scripts/handle_tmux_automatic_start/systemd_enable.sh +++ b/scripts/handle_tmux_automatic_start/systemd_enable.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash CURRENT_DIR="$( dirname ${BASH_SOURCE[0]} )" +PARENT_DIR="${CURRENT_DIR%/*}" -source "$CURRENT_DIR/../helpers.sh" -source "$CURRENT_DIR/../variables.sh" +source "${PARENT_DIR}/helpers.sh" +source "${PARENT_DIR}/variables.sh" template() { local tmux_start_script="$1" @@ -19,7 +20,7 @@ template() { [Service] Type=forking Environment=DISPLAY=:0 - ExecStart=${systemd_tmux_server_start_cmd} + ExecStart=${PARENT_DIR}/continuum_start.sh ExecStop=${HOME}/.tmux/plugins/tmux-resurrect/scripts/save.sh ExecStop=/usr/bin/tmux kill-server @@ -46,14 +47,9 @@ enable_tmux_unit_on_boot() { main() { local options="$(get_tmux_option "$auto_start_config_option" "${auto_start_config_default}")" - # start tmux with a temporary session - local systemd_tmux_server_start_cmd_default="/usr/bin/tmux $(get_tmux_option "${systemd_tmux_server_start_cmd_option}" "${systemd_tmux_server_start_cmd_default}" ) -s ${tmux_server_session_temporary}" - # adds sleep to give tmux some time to finish dettached subprocess "fetch_and_run_tmux_resurrect_restore_script" - # and kills tmux temporary session - local systemd_tmux_server_start_cmd="${systemd_tmux_server_start_cmd_default} && sleep 2 && /usr/bin/tmux kill-session -t ${tmux_server_session_temporary}" local tmux_start_script_path="${CURRENT_DIR}/linux_start_tmux.sh" local systemd_unit_file=$(template "${tmux_start_script_path}" "${options}") - mkdir -p "$(dirname ${systemd_unit_file_path})" + [ ! -d "$(dirname ${systemd_unit_file_path})" ] && mkdir -p "$(dirname ${systemd_unit_file_path})" echo "$systemd_unit_file" > "${systemd_unit_file_path}" enable_tmux_unit_on_boot } diff --git a/scripts/variables.sh b/scripts/variables.sh index 33d98ed..3085cc0 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -38,4 +38,4 @@ systemd_unit_file_path="$HOME/.config/systemd/user/${systemd_service_name}" tmux_server_session_temporary="tmux-continuum-tmp" systemd_tmux_server_start_cmd_option="@continuum-systemd-start-cmd" -systemd_tmux_server_start_cmd_default="new-session -d" +systemd_tmux_server_start_cmd_default="new-session -d -s ${tmux_server_session_temporary}" From 28a76630149b9029216e31090f44155550f9211d Mon Sep 17 00:00:00 2001 From: aguy tech Date: Tue, 24 Nov 2020 09:57:51 +0100 Subject: [PATCH 4/5] systemd-enable: modify the property type to 'mixed' to disable systemd alert --- scripts/handle_tmux_automatic_start/systemd_enable.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/handle_tmux_automatic_start/systemd_enable.sh b/scripts/handle_tmux_automatic_start/systemd_enable.sh index 390f44b..80476b9 100755 --- a/scripts/handle_tmux_automatic_start/systemd_enable.sh +++ b/scripts/handle_tmux_automatic_start/systemd_enable.sh @@ -24,7 +24,7 @@ template() { ExecStop=${HOME}/.tmux/plugins/tmux-resurrect/scripts/save.sh ExecStop=/usr/bin/tmux kill-server - KillMode=none + KillMode=mixed RestartSec=2 From 83c5dd098d48a91653f75b881867c516cc61aec2 Mon Sep 17 00:00:00 2001 From: aguy tech Date: Tue, 8 Dec 2020 09:36:05 +0100 Subject: [PATCH 5/5] Remove trailing log minor correction on creating new session --- scripts/continuum_start.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/continuum_start.sh b/scripts/continuum_start.sh index b7fad10..fe7e99f 100755 --- a/scripts/continuum_start.sh +++ b/scripts/continuum_start.sh @@ -2,8 +2,6 @@ CURRENT_DIR="$( dirname "$0" )" -echo -e "\n$(date +%T) IN" >> /tmp/continuum - source "$CURRENT_DIR/helpers.sh" source "$CURRENT_DIR/variables.sh" @@ -16,12 +14,10 @@ clean_session() { local sessions_count="$(tmux list-sessions 2>/dev/null | wc -l)" if /usr/bin/tmux has-session -t "${tmux_server_session_temporary}"; then - # add a new session to preserve server daemon - [ "${sessions_count}" = 1 ] && tmux new-session -d && \ - echo "$(date +%T) add session" >> /tmp/continuum + # add a new session to preserve server daemon when killing temporary session + [ "${sessions_count}" = 1 ] && tmux new-session # kill session - echo "$(date +%T) kill session" >> /tmp/continuum /usr/bin/tmux kill-session -t "${tmux_server_session_temporary}" fi }