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) 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) 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) 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.
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 starts the services saved to start with lich whose project has a tab open. One that fails to start is logged and shown failed; it does not hold up the others.
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) 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) 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
}
Store is where services are saved, and the projects they run in.