service

package
v0.0.0-...-63dd1cf Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package service provides systemd service management operations. Supports listing, inspecting, and controlling systemd services, and managing custom unit files in /etc/systemd/system/. Delegates unit file writes to the file provider for SHA tracking, idempotency, and template rendering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionResult

type ActionResult struct {
	Name    string `json:"name"`
	Changed bool   `json:"changed"`
}

ActionResult represents the outcome of a service control action.

type CreateResult

type CreateResult struct {
	Name    string `json:"name"`
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

CreateResult represents the outcome of a unit file creation.

type Darwin

type Darwin struct{}

Darwin implements the Provider interface for Darwin (macOS). All methods return ErrUnsupported as service management is not available on macOS.

func NewDarwinProvider

func NewDarwinProvider() *Darwin

NewDarwinProvider factory to create a new Darwin instance.

func (*Darwin) Create

func (d *Darwin) Create(
	_ context.Context,
	_ Entry,
) (*CreateResult, error)

Create returns ErrUnsupported on Darwin.

func (*Darwin) Delete

func (d *Darwin) Delete(
	_ context.Context,
	_ string,
) (*DeleteResult, error)

Delete returns ErrUnsupported on Darwin.

func (*Darwin) Disable

func (d *Darwin) Disable(
	_ context.Context,
	_ string,
) (*ActionResult, error)

Disable returns ErrUnsupported on Darwin.

func (*Darwin) Enable

func (d *Darwin) Enable(
	_ context.Context,
	_ string,
) (*ActionResult, error)

Enable returns ErrUnsupported on Darwin.

func (*Darwin) Get

func (d *Darwin) Get(
	_ context.Context,
	_ string,
) (*Info, error)

Get returns ErrUnsupported on Darwin.

func (*Darwin) List

func (d *Darwin) List(
	_ context.Context,
) ([]Info, error)

List returns ErrUnsupported on Darwin.

func (*Darwin) Restart

func (d *Darwin) Restart(
	_ context.Context,
	_ string,
) (*ActionResult, error)

Restart returns ErrUnsupported on Darwin.

func (*Darwin) Start

func (d *Darwin) Start(
	_ context.Context,
	_ string,
) (*ActionResult, error)

Start returns ErrUnsupported on Darwin.

func (*Darwin) Stop

func (d *Darwin) Stop(
	_ context.Context,
	_ string,
) (*ActionResult, error)

Stop returns ErrUnsupported on Darwin.

func (*Darwin) Update

func (d *Darwin) Update(
	_ context.Context,
	_ Entry,
) (*UpdateResult, error)

Update returns ErrUnsupported on Darwin.

type Debian

type Debian struct {
	provider.FactsAware
	// contains filtered or unexported fields
}

Debian implements the Provider interface for Debian-family systems. It delegates unit file writes to a FileDeployer for SHA tracking and idempotency. Service control operations use systemctl via exec.Manager.

func NewDebianProvider

func NewDebianProvider(
	logger *slog.Logger,
	fs avfs.VFS,
	fileDeployer file.Deployer,
	stateKV jetstream.KeyValue,
	execManager exec.Manager,
	hostname string,
) *Debian

NewDebianProvider factory to create a new Debian instance.

func (*Debian) Create

func (d *Debian) Create(
	ctx context.Context,
	entry Entry,
) (*CreateResult, error)

Create deploys a new unit file via the file provider.

func (*Debian) Delete

func (d *Debian) Delete(
	ctx context.Context,
	name string,
) (*DeleteResult, error)

Delete undeploys a unit file via the file provider.

func (*Debian) Disable

func (d *Debian) Disable(
	_ context.Context,
	name string,
) (*ActionResult, error)

Disable disables a systemd service. If the service is already disabled, it returns Changed: false without taking action.

func (*Debian) Enable

func (d *Debian) Enable(
	_ context.Context,
	name string,
) (*ActionResult, error)

Enable enables a systemd service. If the service is already enabled, it returns Changed: false without taking action.

func (*Debian) Get

func (d *Debian) Get(
	_ context.Context,
	name string,
) (*Info, error)

Get returns a single systemd service by name using systemctl show.

func (*Debian) List

func (d *Debian) List(
	_ context.Context,
) ([]Info, error)

List returns all systemd services by merging list-units and list-unit-files output.

func (*Debian) Restart

func (d *Debian) Restart(
	_ context.Context,
	name string,
) (*ActionResult, error)

Restart restarts a systemd service. Always returns Changed: true on success.

func (*Debian) Start

func (d *Debian) Start(
	_ context.Context,
	name string,
) (*ActionResult, error)

Start starts a systemd service. If the service is already active, it returns Changed: false without taking action.

func (*Debian) Stop

func (d *Debian) Stop(
	_ context.Context,
	name string,
) (*ActionResult, error)

Stop stops a systemd service. If the service is already inactive, it returns Changed: false without taking action.

func (*Debian) Update

func (d *Debian) Update(
	ctx context.Context,
	entry Entry,
) (*UpdateResult, error)

Update redeploys an existing unit file via the file provider.

type DeleteResult

type DeleteResult struct {
	Name    string `json:"name"`
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

DeleteResult represents the outcome of a unit file deletion.

type Entry

type Entry struct {
	Name   string `json:"name"`
	Object string `json:"object,omitempty"`
}

Entry represents a unit file deployment request.

type Info

type Info struct {
	Name        string `json:"name"`
	Status      string `json:"status"`
	Enabled     bool   `json:"enabled"`
	Description string `json:"description,omitempty"`
	PID         int    `json:"pid,omitempty"`
}

Info represents a systemd service.

type Linux

type Linux struct{}

Linux implements the Provider interface for generic Linux. All methods return ErrUnsupported as this is a generic Linux stub.

func NewLinuxProvider

func NewLinuxProvider() *Linux

NewLinuxProvider factory to create a new Linux instance.

func (*Linux) Create

func (l *Linux) Create(
	_ context.Context,
	_ Entry,
) (*CreateResult, error)

Create returns ErrUnsupported on generic Linux.

func (*Linux) Delete

func (l *Linux) Delete(
	_ context.Context,
	_ string,
) (*DeleteResult, error)

Delete returns ErrUnsupported on generic Linux.

func (*Linux) Disable

func (l *Linux) Disable(
	_ context.Context,
	_ string,
) (*ActionResult, error)

Disable returns ErrUnsupported on generic Linux.

func (*Linux) Enable

func (l *Linux) Enable(
	_ context.Context,
	_ string,
) (*ActionResult, error)

Enable returns ErrUnsupported on generic Linux.

func (*Linux) Get

func (l *Linux) Get(
	_ context.Context,
	_ string,
) (*Info, error)

Get returns ErrUnsupported on generic Linux.

func (*Linux) List

func (l *Linux) List(
	_ context.Context,
) ([]Info, error)

List returns ErrUnsupported on generic Linux.

func (*Linux) Restart

func (l *Linux) Restart(
	_ context.Context,
	_ string,
) (*ActionResult, error)

Restart returns ErrUnsupported on generic Linux.

func (*Linux) Start

func (l *Linux) Start(
	_ context.Context,
	_ string,
) (*ActionResult, error)

Start returns ErrUnsupported on generic Linux.

func (*Linux) Stop

func (l *Linux) Stop(
	_ context.Context,
	_ string,
) (*ActionResult, error)

Stop returns ErrUnsupported on generic Linux.

func (*Linux) Update

func (l *Linux) Update(
	_ context.Context,
	_ Entry,
) (*UpdateResult, error)

Update returns ErrUnsupported on generic Linux.

type Provider

type Provider interface {
	// List returns all systemd services.
	List(ctx context.Context) ([]Info, error)
	// Get returns a single systemd service by name.
	Get(ctx context.Context, name string) (*Info, error)
	// Create deploys a new unit file via the file provider.
	Create(ctx context.Context, entry Entry) (*CreateResult, error)
	// Update redeploys an existing unit file via the file provider.
	Update(ctx context.Context, entry Entry) (*UpdateResult, error)
	// Delete undeploys a unit file via the file provider.
	Delete(ctx context.Context, name string) (*DeleteResult, error)
	// Start starts a systemd service.
	Start(ctx context.Context, name string) (*ActionResult, error)
	// Stop stops a systemd service.
	Stop(ctx context.Context, name string) (*ActionResult, error)
	// Restart restarts a systemd service.
	Restart(ctx context.Context, name string) (*ActionResult, error)
	// Enable enables a systemd service.
	Enable(ctx context.Context, name string) (*ActionResult, error)
	// Disable disables a systemd service.
	Disable(ctx context.Context, name string) (*ActionResult, error)
}

Provider implements systemd service management operations.

type UpdateResult

type UpdateResult struct {
	Name    string `json:"name"`
	Changed bool   `json:"changed"`
	Error   string `json:"error,omitempty"`
}

UpdateResult represents the outcome of a unit file update.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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