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

Conversation

aguytech
Copy link

The purpose of this modification is to allow session restoration on linux: the way are to :

  • Create a labeled session "${tmux_server_session_temporary}" on start of tmux daemon

Let plugin script "restore.sh" restore tmux session

  • Clean restored session by remove the temporary session "${tmux_server_session_temporary}" which having served to load the tmux daemon

After the start of tmux daemon, start simply tmux with the following command in a terminal console :
tmux a / attach / attach-session
or automate the start of tmux in terminal with adding line to the .basrhrc user file:
type tmux &>/dev/null && tmux ls &>/dev/null && [ -z $TMUX ] && [[ ! $TERM =~ screen ]] && tmux attach-session

;o)

@bruno-
Copy link
Member

bruno- commented Nov 22, 2020

So, why is new-session -d not doing the trick?

Let plugin script "restore.sh" restore tmux session

Note that if someone is running tmux plugins in the background via run -b (eg run -b '~/.tmux/plugins/tpm/tpm') you may end up killing the temporary session immediately after start, before anything is restored.

@aguytech
Copy link
Author

aguytech commented Nov 22, 2020

It's doing the trick, it start the daemon with creation of a NEW session.
At each restart of daemon a new session is created, saved and restored.
x retstarts -> x new sessions.
Not so fun ;o)
A new named session allows it to be deleted immediately after starting the daemon, so that user have just the exact same sessions he left

@aguytech
Copy link
Author

you may end up killing the temporary session immediately after start, before anything is restored.

If you kill the last tmux session, you kill the daemon (on manjaro / ubuntu)

@aguytech
Copy link
Author

Sorry, there is an error in my proposal

I'm working on strongly solution in regards to my comment #7 (comment) and my difficulties to kill-session inside the starting script ...

@@ -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

@@ -19,7 +20,7 @@ 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

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)

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

Copy link
Author

@aguytech aguytech left a comment

Choose a reason for hiding this comment

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

I need to create a named session to allow his deletion after tmux start, otherwise a new session are created at each start of daemon and are added to restored sessions.
If the daemon start with no saved session, I need to create one before to kill the named one, otherwise I kill the server.

To control this deletion of named session I creates a file to control it: 'continuum_start.sh'

@aguytech
Copy link
Author

So, why is new-session -d not doing the trick?

Let plugin script "restore.sh" restore tmux session

Note that if someone is running tmux plugins in the background via run -b (eg run -b '~/.tmux/plugins/tpm/tpm') you may end up killing the temporary session immediately after start, before anything is restored.

You are right about the '-b' option, I made a mistake by forgetting it; o)

@aguytech aguytech changed the title Linux: Modifications to allow session restoration Systemd: Modifications to remove new session after restoration Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants