restart

package
v0.71.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package restart owns how a running lich ends and how its window comes and goes. The backend outlives its window (Window); it ends only when stopped, by `lich quit`, a signal, or a restart: a detached successor is started and this process is stopped, freeing the pinned listener port for the successor to bind. The restart is what the POST /restart endpoint drives after install.sh replaces the binary on disk.

Index

Constants

View Source
const ArgsEnv = "LICH_RELAUNCH_ARGS"

ArgsEnv carries a lich's arguments, as a JSON list, to the lich Inno Setup launches again after an update on Windows. That launch has a fixed command line (build/windows/lich.iss) and the environment of the lich that started the installer, so the window's switches ride the environment (LaunchArgs).

View Source
const WaitEnv = "LICH_RESTART_WAIT"

WaitEnv marks a lich process spawned to succeed a restarting one. The listener bind path retries while this is set, because the outgoing process still holds the pinned port for a moment (see internal/terminal transport).

Variables

View Source
var ErrNoWindow = errors.New("no lich window is open")

ErrNoWindow is Dismiss with no window up to close. It reaches a client only as the RPC's error text, which is what `lich native` matches it by.

Functions

func LaunchArgs

func LaunchArgs(argv []string, getenv func(string) string) ([]string, error)

LaunchArgs are the arguments this lich runs with: its own argv when it has one, and otherwise the ones a lich updating on Windows handed it through ArgsEnv. An ArgsEnv that is not a JSON list of strings is an error.

func StartDetached

func StartDetached(exe string, env, args []string) error

StartDetached launches exe detached, so it outlives this process. stdio is left nil: the successor logs to its own file (main's logging.Init), like any lich launch.

func StartNative

func StartNative(exe string, env []string, logDir string) (*exec.Cmd, error)

StartNative launches the native window exe detached, its stdout and stderr appended to the native log under logDir (logging.OpenNative): detached, it has no terminal, and what it prints would otherwise go nowhere.

func WatchNative

func WatchNative(cmd *exec.Cmd)

WatchNative waits for the native window cmd, already started, to exit and logs how it ended, an exit code or the signal that killed it, with the last memory reading taken while it ran (Linux only). Waiting also reaps it: an exited window no one waits on stays a zombie under the backend.

func WithoutMarker

func WithoutMarker(env []string) []string

WithoutMarker is env minus the wait marker and ArgsEnv, on a fresh slice. Both are for this process's own startup alone: what it spawns must not read as a restart successor, or a lich launched from one of its sessions never looks for the running one and dies on the busy port, and it must not take this lich's window switches for its own.

Types

type Coordinator

type Coordinator struct {
	// contains filtered or unexported fields
}

Coordinator ends this lich: on its own (Quit), or after launching a detached successor (Do, Install), so this process unwinds, exits, and frees the port.

func New

func New(exePath string, env, args []string) *Coordinator

New returns a coordinator that relaunches exePath with env (plus the wait marker) and args. env should be the current process environment so the successor pins the same listener port; args are what the successor is launched with (chromium.RelaunchArgs), nil for none.

func (*Coordinator) Do

func (c *Coordinator) Do() error

Do launches the successor and stops this lich. Order matters: the successor starts first and blocks retrying the pinned port; then this process exits, and the freed port lets the successor bind and open a fresh window.

func (*Coordinator) Install

func (c *Coordinator) Install(installer string) error

Install hands replacement and relaunch to Inno Setup. It waits for this PID to exit before touching files, so the window and main's defers finish first.

func (*Coordinator) Quit

func (c *Coordinator) Quit() error

Quit ends this lich: every session goes with it, and nothing is launched in its place.

func (*Coordinator) Relaunching

func (c *Coordinator) Relaunching() bool

Relaunching reports whether a successor was launched to take this lich's place, which is what tells a restart from a quit once lich is stopping.

func (*Coordinator) SetStop

func (c *Coordinator) SetStop(stop func())

SetStop supplies the clean exit: stop makes main close the window, unwind its defers and return. Called once lich is serving; a restart before that only spawns the successor.

func (*Coordinator) SetWindowOpen

func (c *Coordinator) SetWindowOpen(open func() bool)

SetWindowOpen supplies whether lich's window is up when a restart happens. With none up the successor starts without one as well: whatever client was on this backend instead (`lich native`'s window) reconnects to the successor, and a web window opening in its place would take its sockets.

type Window

type Window struct {
	// contains filtered or unexported fields
}

Window is lich's window over a backend that outlives it. Closing the window leaves the backend and its sessions running; Show opens a new one on them, or brings forward the one already open. At most one is open at a time.

func NewWindow

func NewWindow(run func(focus string, onStart func(close func() error)) error, focus func(), ended func(WindowEnd)) *Window

NewWindow returns a keeper with no window open. run opens one, on a session's card when it names one, and blocks until it ends; focus brings an open one forward, and ended is called, on the window's own goroutine, each time one ends.

func (*Window) Close

func (w *Window) Close()

Close asks the open window to close and waits, up to closeWait, for it to go. It is the way out of a quitting lich: the window is closed rather than left to die with the process, so Chromium flushes the profile first.

func (*Window) Dismiss

func (w *Window) Dismiss() error

Dismiss closes the open window and leaves lich running, which is what the page asks for when the user answers that lich keeps running in the background. The window's end is reported like any other close.

func (*Window) Open

func (w *Window) Open() bool

Open reports whether a window is open or on its way up.

func (*Window) Show

func (w *Window) Show()

Show opens a window when none is open, and brings the open one forward otherwise. A window still starting is left to finish: focusing it then would race its own launch for the profile.

func (*Window) ShowSession

func (w *Window) ShowSession(id string)

ShowSession is Show for someone pointing at one session's card. A window it opens starts on that card: the event that opens a card in an open window is sent before a new page is there to hear it. An open window is only brought forward; the event is what moves it to the card.

type WindowEnd

type WindowEnd struct {
	Err       error
	First     bool
	Uptime    time.Duration
	Dismissed bool
}

WindowEnd is how one window ended: what its run returned, whether it was the first window this lich opened, how long it ran, and whether Dismiss closed it rather than the user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL