Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systemd: Modifications to remove new session after restoration #83

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions scripts/continuum_start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

CURRENT_DIR="$( dirname "$0" )"

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 when killing temporary session
[ "${sessions_count}" = 1 ] && tmux new-session

# kill session
/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
12 changes: 6 additions & 6 deletions scripts/handle_tmux_automatic_start/systemd_enable.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env bash

CURRENT_DIR="$( dirname ${BASH_SOURCE[0]} )"
PARENT_DIR="${CURRENT_DIR%/*}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set a parent properly


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"
Expand All @@ -19,11 +20,11 @@ template() {
[Service]
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/tmux ${systemd_tmux_server_start_cmd}
ExecStart=${PARENT_DIR}/continuum_start.sh
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a local script to start tmux daemon in place a /usr/bin/tmux


ExecStop=${HOME}/.tmux/plugins/tmux-resurrect/scripts/save.sh
ExecStop=/usr/bin/tmux kill-server
KillMode=none
KillMode=mixed

RestartSec=2

Expand All @@ -46,10 +47,9 @@ 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}" )"
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})"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevent error when creates existing path (script is executed at each start)

echo "$systemd_unit_file" > "${systemd_unit_file_path}"
enable_tmux_unit_on_boot
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="new-session -d -s ${tmux_server_session_temporary}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starts the daemon with a named session to allow to kill it after starting