Skip to content

Commit e98320e

Browse files
committed
ops: fix tmux visibility with systemd PrivateTmp
systemd's PrivateTmp=yes creates a private /tmp namespace, making tmux sockets invisible from outside the service. baudbot attach, sessions, and logs all failed to find tmux sessions. Fix: set TMUX_TMPDIR=~/.tmux-sock in start.sh so tmux sockets land in a visible directory. Add agent_tmux() helper in the dispatcher that sets the same TMUX_TMPDIR when running tmux as the agent.
1 parent f4c3c2b commit e98320e

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

bin/baudbot

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ usage() {
6868
echo " --help, -h Show this help"
6969
}
7070

71+
# Run tmux as the agent user with the correct socket dir.
72+
# systemd's PrivateTmp hides /tmp, so tmux sockets live in ~/.tmux-sock/
73+
agent_tmux() {
74+
local agent_home
75+
agent_home=$(getent passwd baudbot_agent | cut -d: -f6 2>/dev/null || echo "/home/baudbot_agent")
76+
sudo -u baudbot_agent env TMUX_TMPDIR="$agent_home/.tmux-sock" tmux "$@"
77+
}
78+
7179
require_root() {
7280
if [ "$(id -u)" -ne 0 ]; then
7381
echo "❌ baudbot $1 requires root. Run: sudo baudbot $1"
@@ -142,7 +150,7 @@ case "${1:-}" in
142150
exec journalctl -u baudbot -f "$@"
143151
else
144152
echo "No systemd unit. Check tmux sessions:"
145-
echo " sudo -u baudbot_agent tmux ls"
153+
echo " sudo baudbot sessions"
146154
fi
147155
;;
148156

@@ -151,7 +159,7 @@ case "${1:-}" in
151159
require_root "sessions"
152160
AGENT_USER="baudbot_agent"
153161
echo -e "${BOLD}tmux sessions:${RESET}"
154-
if sudo -u "$AGENT_USER" tmux ls 2>/dev/null; then
162+
if agent_tmux ls 2>/dev/null; then
155163
:
156164
else
157165
echo " (none)"
@@ -210,7 +218,7 @@ case "${1:-}" in
210218
TARGET="${1:-}"
211219
if [ -z "$TARGET" ]; then
212220
# Default: attach to first available tmux session
213-
FIRST_SESSION=$(sudo -u "$AGENT_USER" tmux ls -F '#{session_name}' 2>/dev/null | head -1)
221+
FIRST_SESSION=$(agent_tmux ls -F '#{session_name}' 2>/dev/null | head -1)
214222
if [ -n "$FIRST_SESSION" ]; then
215223
TARGET="$FIRST_SESSION"
216224
else
@@ -222,7 +230,7 @@ case "${1:-}" in
222230
echo "Attaching to tmux session: $TARGET"
223231
echo "Detach with: Ctrl+b, d"
224232
echo ""
225-
exec sudo -u "$AGENT_USER" tmux attach-session -t "$TARGET"
233+
exec agent_tmux attach-session -t "$TARGET"
226234
;;
227235

228236
setup)

start.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ cd ~
1616
# Set PATH
1717
export PATH="$HOME/.varlock/bin:$HOME/opt/node-v22.14.0-linux-x64/bin:$PATH"
1818

19+
# systemd's PrivateTmp=yes hides /tmp from outside the service.
20+
# Point tmux at a visible directory so baudbot attach/sessions work.
21+
export TMUX_TMPDIR="$HOME/.tmux-sock"
22+
mkdir -p "$TMUX_TMPDIR"
23+
chmod 700 "$TMUX_TMPDIR"
24+
1925
# Validate and load secrets via varlock
2026
varlock load --path ~/.config/ || {
2127
echo "❌ Environment validation failed — check ~/.config/.env against .env.schema"

0 commit comments

Comments
 (0)