Documentation
¶
Overview ¶
Package serviceops contains the shared business logic for installing, starting, stopping, and removing lerd services. The CLI commands and the MCP tools both call into here so they enforce identical preset gating, dependency cascades, and dynamic_env regeneration.
Index ¶
- func EnsureCustomServiceQuadlet(svc *config.CustomService) error
- func EnsureDefaultPresetQuadlet(name string) error
- func EnsureServiceRunning(name string) error
- func InstallPresetByName(name, version string) (*config.CustomService, error)
- func InstallPresetStreaming(name, version string, emit func(PhaseEvent)) (*config.CustomService, error)
- func IsBuiltin(name string) bool
- func MigrateService(name, targetImage string, emit func(PhaseEvent)) error
- func MissingPresetDependencies(svc *config.CustomService) []string
- func RegenerateFamilyConsumers(family string)
- func RegenerateFamilyConsumersForService(name string)
- func RollbackService(name string, emit func(PhaseEvent)) error
- func ServiceFamily(name string) string
- func StartDependencies(svc *config.CustomService) error
- func StopWithDependents(name string)
- func SupportsMigration(name string) bool
- func UpdateServiceStreaming(name, targetImage string, emit func(PhaseEvent)) error
- type PhaseEvent
- type UpdateAvailability
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureCustomServiceQuadlet ¶
func EnsureCustomServiceQuadlet(svc *config.CustomService) error
EnsureCustomServiceQuadlet writes the quadlet for a custom service and reloads systemd only when the file actually changed on disk. Materialises any declared file mounts and resolves dynamic_env directives so the rendered quadlet has the computed values.
func EnsureDefaultPresetQuadlet ¶
EnsureDefaultPresetQuadlet writes the quadlet for a default-preset service (mysql, postgres, redis, ...) by resolving the canonical CustomService from its YAML preset, layering the user's image / extra-port overrides from global config, applying the platform-specific image override last (matching the legacy "platform override wins" semantics), and finally writing through the shared custom-service quadlet writer.
This replaces the older embedded-template flow (cli.ensureServiceQuadlet) so default services and add-on presets share one code path.
func EnsureServiceRunning ¶
EnsureServiceRunning starts the service if it is not already active and waits until it is ready. Recurses through depends_on for custom services.
func InstallPresetByName ¶
func InstallPresetByName(name, version string) (*config.CustomService, error)
InstallPresetByName materialises a bundled preset as a custom service. version selects a tag for multi-version presets; empty falls back to the preset's DefaultVersion.
func InstallPresetStreaming ¶ added in v1.18.0
func InstallPresetStreaming(name, version string, emit func(PhaseEvent)) (*config.CustomService, error)
InstallPresetStreaming runs the full install flow and emits a PhaseEvent at every step. The image is pulled before StartUnit so the hidden on-demand pull latency becomes visible progress in the UI.
func IsBuiltin ¶
IsBuiltin reports whether name is a built-in (default-preset) lerd service. Kept as a passthrough so callers don't have to import config.
func MigrateService ¶
func MigrateService(name, targetImage string, emit func(PhaseEvent)) error
MigrateService runs a per-family dump/restore migration so the service can move across data-incompatible SQL versions (e.g. mysql 8.0 → 9.0). Errors when no handler is registered for the service family.
func MissingPresetDependencies ¶
func MissingPresetDependencies(svc *config.CustomService) []string
MissingPresetDependencies returns the names of services that svc declares in depends_on but which are neither built-in nor already installed as custom services.
func RegenerateFamilyConsumers ¶
func RegenerateFamilyConsumers(family string)
RegenerateFamilyConsumers re-renders the quadlet of any installed custom service whose dynamic_env references the named family. Active consumers are stopped, removed, and started so the new generated unit is the one systemd loads.
func RegenerateFamilyConsumersForService ¶
func RegenerateFamilyConsumersForService(name string)
RegenerateFamilyConsumersForService is a convenience that wraps RegenerateFamilyConsumers in a no-op when name has no recognised family.
func RollbackService ¶
func RollbackService(name string, emit func(PhaseEvent)) error
RollbackService swaps a service back to its previously-running image. Refuses when no previous image is recorded or when the most recent op was a migrate (binary/schema mismatch would corrupt the data dir).
func ServiceFamily ¶
ServiceFamily returns the family of a service by name. Honours the explicit Family field on a custom service first, falls back to config.InferFamily for built-ins and pattern-matched alternates.
func StartDependencies ¶
func StartDependencies(svc *config.CustomService) error
StartDependencies ensures every entry in svc.DependsOn is up and ready before the parent is started.
func StopWithDependents ¶
func StopWithDependents(name string)
StopWithDependents stops every custom service that depends on name (depth-first), then stops name itself.
func SupportsMigration ¶
SupportsMigration reports whether a registered family migrator exists for the named service.
func UpdateServiceStreaming ¶
func UpdateServiceStreaming(name, targetImage string, emit func(PhaseEvent)) error
UpdateServiceStreaming pulls the chosen image, persists it, rewrites the quadlet, and restarts the unit. Phases: checking_registry, pulling_image, writing_quadlet, restarting_unit, done.
Types ¶
type PhaseEvent ¶ added in v1.18.0
type PhaseEvent struct {
Phase string `json:"phase"`
Image string `json:"image,omitempty"`
Message string `json:"message,omitempty"`
Dep string `json:"dep,omitempty"`
State string `json:"state,omitempty"`
Unit string `json:"unit,omitempty"`
}
PhaseEvent is one step of the streaming preset-install flow.
type UpdateAvailability ¶
type UpdateAvailability struct {
Service string `json:"service"`
CurrentImage string `json:"current_image"`
CurrentTag string `json:"current_tag"`
LatestTag string `json:"latest_tag,omitempty"`
LatestImage string `json:"latest_image,omitempty"`
Available bool `json:"available"`
Strategy string `json:"strategy"`
UpgradeTag string `json:"upgrade_tag,omitempty"`
UpgradeImage string `json:"upgrade_image,omitempty"`
PreviousImage string `json:"previous_image,omitempty"`
// CanRollback is false when the most recent op was a migrate (rolling the
// image back without restoring the pre-migrate data dir would corrupt it).
CanRollback bool `json:"can_rollback"`
}
UpdateAvailability is the metadata returned by CheckUpdateAvailable so the UI can render an "update available → v8.4.3" badge without applying it.
func CheckUpdateAvailable ¶
func CheckUpdateAvailable(name string) (*UpdateAvailability, error)
CheckUpdateAvailable queries the registry for a newer tag matching the preset's update_strategy. Network and unsupported-registry errors are swallowed so the UI stays quiet on offline / custom-registry installs. Successful results are cached for updateAvailabilityTTL so snapshot rebuilds don't fork a `podman image inspect` per service per rebuild.