Documentation
¶
Overview ¶
Package restore brings the working set of terminals back after the tmux server died (host reboot, tmux kill-server): coders are resumed, shells are recreated. A snapshot of the live terminals is kept current in the state dir; the startup pass replays it when the terminal restore setting is on. A plain dev-cockpit restart leaves tmux untouched, then every recorded terminal is still running and the pass changes nothing.
Index ¶
Constants ¶
const SettingKey = "terminal-restore"
SettingKey is the settings store key that switches the startup restore on (value "on"). Unset or anything else means off. The snapshot file is written regardless of the setting, so enabling it acts on current data.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Kind string `json:"kind"` // "coder" or "shell"
Coder string `json:"coder,omitempty"` // owning coder id, coders only
ID string `json:"id,omitempty"` // coder resume key, or the shell session id recreated verbatim
Name string `json:"name"` // display name; for coders the resumable store name wins
CWD string `json:"cwd"` // start directory
Pos int `json:"pos,omitempty"` // @dc_tab_pos at snapshot time, 0 when unset
Group string `json:"group,omitempty"` // @dc_tab_group at snapshot time, empty when ungrouped
GPos int `json:"gpos,omitempty"` // @dc_tab_gpos at snapshot time, 0 when unset
GName string `json:"gname,omitempty"` // @dc_tab_gname at snapshot time, may be empty
GCol int `json:"gcol,omitempty"` // @dc_tab_gcol at snapshot time, 0 for a column of its own
}
Entry is one recorded terminal in the snapshot file.
type Jobs ¶
Jobs is the assistant's job store, as much of it as the startup pass needs: the entries of terminals that are gone are dropped there like the notifications are. An interface, so the restore does not have to know the assistant.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service keeps the terminal snapshot current and replays it at startup. Safe for concurrent use.
func New ¶
func New(path string, enabled func() bool, coders []*coder.Manager, shells *shell.Shells, t *tmux.Client, notifier *notify.Service, jobs Jobs, projects func() []string) *Service
New wires up the service. path is the snapshot file, enabled reads the setting on every call. projects lists the names of the existing projects, injected as a function so restore needs no import on project: the prune keeps the per project notification targets of exactly these.
func (*Service) RunPeriodic ¶
RunPeriodic rewrites the snapshot every interval. Never returns, run it on a goroutine.
func (*Service) RunStartup ¶
func (s *Service) RunStartup()
RunStartup replays the snapshot when the setting is on: recorded coders that are not running are resumed if their id is still in the coder's resumable store, recorded shells that are not running are recreated in their directory under their recorded id, so links, open tabs, and notification entries keep resolving (skipped when the directory is gone). The recorded tab position is re-applied. A recreated shell is a fresh bash, its output is gone, so its notifications are marked read instead of ringing for nothing. Notification entries and closed job entries whose target resolves to nothing are pruned and the snapshot is rewritten from a fresh scan; both run on every startup, also with the setting off, so dead entries clean themselves up regardless of the restore.
func (*Service) Write ¶
func (s *Service) Write()
Write rewrites the snapshot from the live terminals. Called on every terminal mutation plus the periodic refresh, since sessions can change behind dev-cockpit's back and a crash announces nothing, the file must always be near-current. An unchanged scan writes nothing.