feat(systemd): auto-start tmux main session at login and add dotfiles restore unit
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
../tmux-main.service
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Restore dotfiles into home directory
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/bin/stow --dotfiles --dir=/home/sjb/.local/share/dotfiles --restow packages apps config
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Ensure tmux session "main" is running
|
||||||
|
After=graphical-session.target
|
||||||
|
PartOf=graphical-session.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
|
ExecStart=%h/.local/share/dotfiles/script/tmux-start.sh
|
||||||
|
# If the session check fails (no server / lost session), retry until login ends.
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
||||||
Executable
+17
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Start (or reuse) the tmux server with a session named "main".
|
||||||
|
# Used by the tmux-main systemd user service at graphical login.
|
||||||
|
#
|
||||||
|
# Designed to survive Restart=on-failure: if a session already exists this
|
||||||
|
# script reattaches nothing and exits 0; if the server dies systemd restarts
|
||||||
|
# us and we recreate the session.
|
||||||
|
set -u
|
||||||
|
|
||||||
|
session=main
|
||||||
|
|
||||||
|
if ! tmux ls 2>/dev/null | grep -q "^${session}:"; then
|
||||||
|
tmux new-session -d -s "$session"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Keep the unit "active" only briefly; the session lives in the tmux server.
|
||||||
|
exit 0
|
||||||
Reference in New Issue
Block a user