Documentation
¶
Overview ¶
Package restart owns how a running lich ends. The backend outlives its 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
- func Companion(env func(string) string, envName, binary, howToBuild string) (string, error)
- func NativeExecutable(env func(string) string) (string, error)
- func StartDetached(exe string, env, args []string) error
- func StartNative(exe string, env []string, logDir string) (*exec.Cmd, error)
- func WatchNative(cmd *exec.Cmd)
- func WithoutMarker(env []string) []string
- type Coordinator
Constants ¶
const NativeBinary = "lich-native"
NativeBinary is the native window's executable, shipped beside lich's.
const NativeEnv = "LICH_NATIVE"
NativeEnv pins the native window to launch, by path. `go run` and a native build of one's own have no lich-native beside the lich binary.
const NoWindowArg = "--no-window"
NoWindowArg starts lich without its window.
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 ¶
This section is empty.
Functions ¶
func Companion ¶ added in v0.73.0
Companion is the executable pinned by envName, else binary beside this lich binary; howToBuild finishes the sentence a missing one is reported with.
func NativeExecutable ¶ added in v0.73.0
NativeExecutable is the native window's binary: the one NativeEnv pins, else lich-native beside this lich binary. A missing one is an error that says how to get one.
func StartDetached ¶
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 ¶
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 ¶
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 ¶
WithoutMarker is env minus the wait marker, on a fresh slice. The marker is 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.
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 []string) *Coordinator
New returns a coordinator that relaunches exePath with env (plus the wait marker). env should be the current process environment so the successor pins the same listener port.
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. The open window closes with this lich rather than moving onto the successor: a restart follows an update, and the window still running is the old lich-native, whose calls the new backend may no longer take. The successor opens a window from the binary now on disk, and only where one was open.
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 main's defers finish first. The window closes with this lich: the installer replaces lich-native.exe too, which Windows will not overwrite while it runs, and the lich it launches again opens a window of its own.
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) Restarting ¶ added in v0.89.0
func (c *Coordinator) Restarting() bool
Restarting reports whether a successor was launched, which is what tells this lich's way out from a quit.
func (*Coordinator) SetStop ¶
func (c *Coordinator) SetStop(stop func())
SetStop supplies the clean exit: stop makes main 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 a native window is attached, which decides whether a successor opens one.