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 user service display support and manual setup docs #107

Open
wants to merge 3 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
65 changes: 65 additions & 0 deletions docs/systemd_details.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,69 @@ To control the tmux service you can use all the standard `systemctl` commands us

systemctl --user status tmux.service

## 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)
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
```

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

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:
```shell
systemctl --user status tmux.service
```

You should see something along the lines of:
```shell
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-xxxx.slice/[email protected]/app.slice/tmux.service
├─ 6306 /usr/bin/tmux new-session -d
├─ 7735 zsh
...
```
4 changes: 3 additions & 1 deletion scripts/handle_tmux_automatic_start/systemd_enable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down