fix(down): prevent tmux server exit when all sessions killed

When gt down --all killed all Gas Town sessions, if those were the only
tmux sessions, the server would exit due to tmux's default exit-empty
setting. Users perceived this as gt down --all killed my tmux server.

Fix: Set exit-empty off before killing sessions, ensuring the server
stays running for subsequent gt up commands. The --nuke flag still
explicitly kills the server when requested.

Fixes: gt-kh8w47

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gastown/crew/joe
2026-01-17 01:34:27 -08:00
committed by Steve Yegge
parent 885b5023d3
commit 5823c9fb36
2 changed files with 23 additions and 0 deletions

View File

@@ -95,6 +95,12 @@ func runDown(cmd *cobra.Command, args []string) error {
return fmt.Errorf("cannot proceed: %w", err)
}
defer func() { _ = lock.Unlock() }()
// Prevent tmux server from exiting when all sessions are killed.
// By default, tmux exits when there are no sessions (exit-empty on).
// This ensures the server stays running for subsequent `gt up`.
// Ignore errors - if there's no server, nothing to configure.
_ = t.SetExitEmpty(false)
}
allOK := true

View File

@@ -224,6 +224,23 @@ func (t *Tmux) KillServer() error {
return err
}
// SetExitEmpty controls the tmux exit-empty server option.
// When on (default), the server exits when there are no sessions.
// When off, the server stays running even with no sessions.
// This is useful during shutdown to prevent the server from exiting
// when all Gas Town sessions are killed but the user has no other sessions.
func (t *Tmux) SetExitEmpty(on bool) error {
value := "on"
if !on {
value = "off"
}
_, err := t.run("set-option", "-g", "exit-empty", value)
if errors.Is(err, ErrNoServer) {
return nil // No server to configure
}
return err
}
// IsAvailable checks if tmux is installed and can be invoked.
func (t *Tmux) IsAvailable() bool {
cmd := exec.Command("tmux", "-V")