Documentation
¶
Overview ¶
Package services runs a project's services: commands the user saved once (a container, a tunnel, a dev server) that lich starts on a PTY of their own and shows as up or down, outside the session list. A service lives as long as its project's tab: closing the tab stops it, reopening the project starts the ones saved to start with lich, and so does lich starting with the tab open. Closing the window leaves them all running; quitting lich stops them (Shutdown).
A service is not a shell. When its command exits, the service has stopped: nothing is respawned and no prompt is left behind, and what it printed last stays readable (Output) until it starts again.
Index ¶
- Constants
- type Service
- func (s *Service) Boot()
- func (s *Service) BootAfterRestart(wait time.Duration)
- func (s *Service) Delete(_ context.Context, opts api.ServiceIDOptions) (api.None, error)
- func (s *Service) ForceStop(_ context.Context, opts api.ServiceIDOptions) (api.None, error)
- func (s *Service) List(_ context.Context, _ api.None) ([]api.Service, error)
- func (s *Service) LiveOutput(_ context.Context, opts api.ServiceIDOptions) ([]byte, error)
- func (s *Service) Output(_ context.Context, opts api.ServiceIDOptions) ([]byte, error)
- func (s *Service) ProjectChanged(name string, data any)
- func (s *Service) Restart(_ context.Context, opts api.ServiceIDOptions) (api.None, error)
- func (s *Service) Reveal(id string)
- func (s *Service) Running() []api.Service
- func (s *Service) Save(_ context.Context, opts api.SaveServiceOptions) (api.Service, error)
- func (s *Service) Shutdown(grace time.Duration)
- func (s *Service) ShutdownForRestart(grace time.Duration)
- func (s *Service) Start(_ context.Context, opts api.ServiceIDOptions) (api.None, error)
- func (s *Service) StartAll(_ context.Context, opts api.ProjectIDOptions) (api.None, error)
- func (s *Service) Stop(_ context.Context, opts api.ServiceIDOptions) (api.None, error)
- func (s *Service) StopAll(_ context.Context, opts api.ProjectIDOptions) (api.None, error)
- func (s *Service) StopRunning()
- type Store
Constants ¶
const ProjectCloseGrace = 10 * time.Second
ProjectCloseGrace is how long closing a project's tab waits for its services to stop on their own before killing them: Docker's own stop timeout, `docker compose up` being the service this is most often.
const ( // RestartWaitMargin is what a successor adds to the outgoing lich's stop // grace before giving up on its record: the kill after the grace, and the // write that follows it. RestartWaitMargin = killWait + 5*time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the services of every project and the process of each.
func (*Service) Boot ¶
func (s *Service) Boot()
Boot is a plain launch: it starts the services saved to start with lich whose project has a tab open, and drops a record no successor consumed, which must not start anything at this later launch. One that fails to start is logged and shown failed; it does not hold up the others.
func (*Service) BootAfterRestart ¶ added in v0.89.0
BootAfterRestart is the boot of a restart's successor. The outgoing lich has freed the port but is still stopping its services, so a second copy started now would lose the fight for whatever they hold: everything waits for its record, written once they are down.
func (*Service) Delete ¶
Delete removes a service that is not running. One that is running is refused rather than stopped on the way out: stopping can take a command a while, and deleting it under its feet would leave a process nothing lists.
func (*Service) List ¶
List is every service with its state, each project's in the order they were added.
func (*Service) LiveOutput ¶ added in v0.84.0
LiveOutput is what a running service has printed so far, read at the moment of the call: nil once it is not running, when Output has its last run.
func (*Service) Output ¶
Output is what a service printed last, from the moment its last run exited: nil while it runs, its console being live on /ws then, or before it ever ran.
func (*Service) ProjectChanged ¶
ProjectChanged follows the project list (store.SetProjectChanged): a project opened, or reopened, starts its services saved to start with lich, and one closed stops all of its services, off the caller's goroutine either way, since a stop can take grace to finish.
func (*Service) Save ¶
Save writes a service, a new one when opts.ID is empty. The name and the command are trimmed and both are required, and the name must be free in its project: the footer and the tray tell services apart by it. A running service keeps the command it was started with until its next start.
func (*Service) Shutdown ¶
Shutdown stops every running service on lich's way out: asked first, then killed once grace is up, and waited for at most a few seconds more so no process outlives the backend that started it.
func (*Service) ShutdownForRestart ¶ added in v0.89.0
ShutdownForRestart is Shutdown with a successor on its way: what is running now is recorded once it is all down, which is what the successor waits on. A service already stopping was on its way out by the user's hand, so it stays out of the record.
func (*Service) StopRunning ¶
func (s *Service) StopRunning()
StopRunning asks every running service, of every project, to stop.
type Store ¶
type Store interface {
Services() ([]api.ServiceConfig, error)
SaveService(c api.ServiceConfig) error
DeleteService(id string) error
ProjectName(projectID string) string
ProjectPath(projectID string) string
ProjectOpen(projectID string) bool
GetSetting(ctx context.Context, opts api.GetSettingOptions) (string, error)
SetSetting(ctx context.Context, opts api.SetSettingOptions) (api.None, error)
}
Store is where services are saved, and the projects they run in.