From b8358c79efc7404cc535afbe5e9fa477c283e93e Mon Sep 17 00:00:00 2001 From: Sven Vowe Date: Sat, 28 May 2022 14:39:19 +0200 Subject: [PATCH 1/3] docs: added linux systemd setup configuration --- docs/systemd_details.md | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/docs/systemd_details.md b/docs/systemd_details.md index 7b9ed45..5fd7166 100644 --- a/docs/systemd_details.md +++ b/docs/systemd_details.md @@ -10,4 +10,73 @@ To control the tmux service you can use all the standard `systemctl` commands us systemctl --user status tmux.service +## Setup Example +To be able to configure systemd user services, make sure the following directories exist: `$HOME/.config/systemd/user`. If not, just create them: + +```shell +mkdir ~/.config/systemd +mkdir ~/.config/systemd/user +``` + +Create the systemd user service file: + +```shell +touch ~/.config/systemd/user/tmux.service +``` + +The service file can be created from this template: + +```shell +[Unit] +Description=tmux default session (detached) +Documentation=man:tmux(1) +After=graphical.target + +[Service] +Type=forking +Environment=DISPLAY=:1 +ExecStart=/usr/bin/tmux new-session -d + +ExecStop=/home/user/.tmux/plugins/tmux-resurrect/scripts/save.sh +ExecStop=/usr/bin/tmux kill-server +KillMode=mixed + +RestartSec=2 + +[Install] +WantedBy=default.target +``` + +Now make sure you adapt the service file to your needs: + +- `Environment`: Set the value of your $DISPLAY environment variable (i.e. `:1`, to find out run `echo $DISPLAY`) +- `ExecStart`: If you want to configure the tmux start command, you can do it here +- `ExecStop`: Enter the full path to the `save.sh` script of `tmux-resurrect`, usually in `$HOME/.tmux/plugins/tmux-resurrect/scripts/save.sh` +- `After`: Adapt to your needs, waiting for `graphical.target` helps if you want to open gui applications such as `code` directly from your resurrected terminals + +Now you are ready to enable and start your system service: + +```shell +systemctl --user enable tmux.service +systemctl --user start tmux.service +``` + +- Reboot your machine. +- To check the current status of your tmux service, run this command: + +```shell +systemctl --user status tmux.service +``` + +You should see something along the lines of: + +```shell +Active: active (running) since Fri 2022-05-27 15:28:36 CEST; 23h ago + Docs: man:tmux(1) + Process: 6300 ExecStart=/usr/bin/tmux new-session -d (code=exited, status=0/SUCCESS) + CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/tmux.service + ├─ 6306 /usr/bin/tmux new-session -d + ├─ 7735 zsh + ... +``` From f85fc61b60ce5eb5de6f10d48ab98e2cfacfd21a Mon Sep 17 00:00:00 2001 From: Sven Vowe Date: Sat, 28 May 2022 17:41:22 +0200 Subject: [PATCH 2/3] chore: updated systemd user template to include display and target --- scripts/handle_tmux_automatic_start/systemd_enable.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/handle_tmux_automatic_start/systemd_enable.sh b/scripts/handle_tmux_automatic_start/systemd_enable.sh index 77e24eb..b198677 100755 --- a/scripts/handle_tmux_automatic_start/systemd_enable.sh +++ b/scripts/handle_tmux_automatic_start/systemd_enable.sh @@ -12,15 +12,17 @@ template() { local content="" local resurrect_save_script_path="$(get_tmux_option "$resurrect_save_path_option" "$(realpath ${CURRENT_DIR}/../../../tmux-resurrect/scripts/save.sh)")" local tmux_path="$(command -v tmux)" + local display="$DISPLAY" read -r -d '' content <<-EOF [Unit] Description=tmux default session (detached) Documentation=man:tmux(1) + After=graphical.target [Service] Type=forking - Environment=DISPLAY=:0 + Environment=DISPLAY=${display} ExecStart=${tmux_path} ${systemd_tmux_server_start_cmd} ExecStop=${resurrect_save_script_path} From bad218eacf345ab4765a7ef286d044fe7ed50bb2 Mon Sep 17 00:00:00 2001 From: Sven Vowe Date: Sat, 28 May 2022 17:46:48 +0200 Subject: [PATCH 3/3] docs: cleanup and finalization for pr --- docs/systemd_details.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/docs/systemd_details.md b/docs/systemd_details.md index 5fd7166..428c759 100644 --- a/docs/systemd_details.md +++ b/docs/systemd_details.md @@ -10,23 +10,20 @@ To control the tmux service you can use all the standard `systemctl` commands us systemctl --user status tmux.service -## Setup Example - -To be able to configure systemd user services, make sure the following directories exist: `$HOME/.config/systemd/user`. If not, just create them: +## Manual setup example +To be able to configure systemd user services, make sure the following directories exist: `$HOME/.config/systemd/user`. If not, create them: ```shell mkdir ~/.config/systemd mkdir ~/.config/systemd/user ``` Create the systemd user service file: - ```shell touch ~/.config/systemd/user/tmux.service ``` The service file can be created from this template: - ```shell [Unit] Description=tmux default session (detached) @@ -48,34 +45,33 @@ RestartSec=2 WantedBy=default.target ``` -Now make sure you adapt the service file to your needs: +Make sure you adapt the service file to your needs: - `Environment`: Set the value of your $DISPLAY environment variable (i.e. `:1`, to find out run `echo $DISPLAY`) - `ExecStart`: If you want to configure the tmux start command, you can do it here - `ExecStop`: Enter the full path to the `save.sh` script of `tmux-resurrect`, usually in `$HOME/.tmux/plugins/tmux-resurrect/scripts/save.sh` - `After`: Adapt to your needs, waiting for `graphical.target` helps if you want to open gui applications such as `code` directly from your resurrected terminals -Now you are ready to enable and start your system service: +Enable and start your systemd user service: ```shell systemctl --user enable tmux.service systemctl --user start tmux.service ``` -- Reboot your machine. -- To check the current status of your tmux service, run this command: +- Reboot your machine +- To check the current status of your tmux service, run this command: ```shell systemctl --user status tmux.service ``` You should see something along the lines of: - ```shell -Active: active (running) since Fri 2022-05-27 15:28:36 CEST; 23h ago +Active: active (running) Docs: man:tmux(1) Process: 6300 ExecStart=/usr/bin/tmux new-session -d (code=exited, status=0/SUCCESS) - CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/tmux.service + CGroup: /user.slice/user-xxxx.slice/user@xxxx.service/app.slice/tmux.service ├─ 6306 /usr/bin/tmux new-session -d ├─ 7735 zsh ...