unit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateQuadletUnit

func GenerateQuadletUnit(unit QuadletUnit, verbose bool) string

func GetUnitStatus

func GetUnitStatus(unitName string, unitType string) (string, error)

GetUnitStatus - Legacy function for backward compatibility

func ProcessManifests

func ProcessManifests(repo *git.Repository, force bool) error

func ReloadSystemd

func ReloadSystemd() error

ReloadSystemd reloads the systemd configuration

func RestartUnit

func RestartUnit(unitName string, unitType string) error

RestartUnit - Legacy function for backward compatibility

func ShowUnit

func ShowUnit(unitName string, unitType string) error

ShowUnit - Legacy function for backward compatibility

func StartUnit

func StartUnit(unitName string, unitType string) error

StartUnit - Legacy function for backward compatibility

func StopUnit

func StopUnit(unitName string, unitType string) error

StopUnit - Legacy function for backward compatibility

Types

type BaseSystemdUnit added in v0.3.0

type BaseSystemdUnit struct {
	Name string
	Type string
}

BaseSystemdUnit provides common implementation for all systemd units

func (*BaseSystemdUnit) GetServiceName added in v0.3.0

func (u *BaseSystemdUnit) GetServiceName() string

GetServiceName returns the full systemd service name based on unit type

func (*BaseSystemdUnit) GetStatus added in v0.3.0

func (u *BaseSystemdUnit) GetStatus() (string, error)

GetStatus returns the current status of the unit

func (*BaseSystemdUnit) GetUnitName added in v0.3.0

func (u *BaseSystemdUnit) GetUnitName() string

GetUnitName returns the name of the unit

func (*BaseSystemdUnit) GetUnitType added in v0.3.0

func (u *BaseSystemdUnit) GetUnitType() string

GetUnitType returns the type of the unit

func (*BaseSystemdUnit) Restart added in v0.3.0

func (u *BaseSystemdUnit) Restart() error

Restart restarts the unit

func (*BaseSystemdUnit) Show added in v0.3.0

func (u *BaseSystemdUnit) Show() error

Show displays the unit configuration and status

func (*BaseSystemdUnit) Start added in v0.3.0

func (u *BaseSystemdUnit) Start() error

Start starts the unit

func (*BaseSystemdUnit) Stop added in v0.3.0

func (u *BaseSystemdUnit) Stop() error

Stop stops the unit

type Container added in v0.3.0

type Container struct {
	Image           string            `yaml:"image"`
	Label           []string          `yaml:"label"`
	PublishPort     []string          `yaml:"publish"`
	Environment     map[string]string `yaml:"environment"`
	EnvironmentFile string            `yaml:"environment_file"`
	Volume          []string          `yaml:"volume"`
	Network         []string          `yaml:"network"`
	Command         []string          `yaml:"command"`
	Entrypoint      []string          `yaml:"entrypoint"`
	User            string            `yaml:"user"`
	Group           string            `yaml:"group"`
	WorkingDir      string            `yaml:"working_dir"`
	PodmanArgs      []string          `yaml:"podman_args"`
	RunInit         bool              `yaml:"run_init"`
	Notify          bool              `yaml:"notify"`
	Privileged      bool              `yaml:"privileged"`
	ReadOnly        bool              `yaml:"read_only"`
	SecurityLabel   []string          `yaml:"security_label"`
	HostName        string            `yaml:"hostname"`
	Secrets         []Secret          `yaml:"secrets"`

	// Systemd unit properties
	Name     string
	UnitType string
}

Container represents the configuration for a container in a Quadlet unit. It includes settings such as the container image, published ports, environment variables, volumes, networks, command, entrypoint, user, and other container-specific options.

func NewContainer added in v0.3.0

func NewContainer(name string) *Container

NewContainer creates a new Container with the given name

func (*Container) GetServiceName added in v0.3.0

func (c *Container) GetServiceName() string

GetServiceName returns the full systemd service name

func (*Container) GetStatus added in v0.3.0

func (c *Container) GetStatus() (string, error)

GetStatus returns the current status of the unit

func (*Container) GetUnitName added in v0.3.0

func (c *Container) GetUnitName() string

GetUnitName returns the name of the unit

func (*Container) GetUnitType added in v0.3.0

func (c *Container) GetUnitType() string

GetUnitType returns the type of the unit

func (*Container) Restart added in v0.3.0

func (c *Container) Restart() error

Restart restarts the unit

func (*Container) Show added in v0.3.0

func (c *Container) Show() error

Show displays the unit configuration and status

func (*Container) Start added in v0.3.0

func (c *Container) Start() error

Start starts the unit

func (*Container) Stop added in v0.3.0

func (c *Container) Stop() error

Stop stops the unit

type Image added in v0.3.0

type Image struct {
	Image      string   `yaml:"image"`
	PodmanArgs []string `yaml:"podman_args"`

	// Systemd unit properties
	Name     string
	UnitType string
}

Image represents the configuration for an image in a Quadlet unit.

func NewImage added in v0.3.0

func NewImage(name string) *Image

NewImage creates a new Image with the given name

func (*Image) GetServiceName added in v0.3.0

func (i *Image) GetServiceName() string

GetServiceName returns the full systemd service name

func (*Image) GetStatus added in v0.3.0

func (i *Image) GetStatus() (string, error)

GetStatus returns the current status of the unit

func (*Image) GetUnitName added in v0.3.0

func (i *Image) GetUnitName() string

GetUnitName returns the name of the unit

func (*Image) GetUnitType added in v0.3.0

func (i *Image) GetUnitType() string

GetUnitType returns the type of the unit

func (*Image) Restart added in v0.3.0

func (i *Image) Restart() error

Restart restarts the unit

func (*Image) Show added in v0.3.0

func (i *Image) Show() error

Show displays the unit configuration and status

func (*Image) Start added in v0.3.0

func (i *Image) Start() error

Start starts the unit

func (*Image) Stop added in v0.3.0

func (i *Image) Stop() error

Stop stops the unit

type Network added in v0.3.0

type Network struct {
	Label      []string `yaml:"label"`
	Driver     string   `yaml:"driver"`
	Gateway    string   `yaml:"gateway"`
	IPRange    string   `yaml:"ip_range"`
	Subnet     string   `yaml:"subnet"`
	IPv6       bool     `yaml:"ipv6"`
	Internal   bool     `yaml:"internal"`
	DNSEnabled bool     `yaml:"dns_enabled"`
	Options    []string `yaml:"options"`

	// Systemd unit properties
	Name     string
	UnitType string
}

Network represents the configuration for a network in a Quadlet unit.

func NewNetwork added in v0.3.0

func NewNetwork(name string) *Network

NewNetwork creates a new Network with the given name

func (*Network) GetServiceName added in v0.3.0

func (n *Network) GetServiceName() string

GetServiceName returns the full systemd service name

func (*Network) GetStatus added in v0.3.0

func (n *Network) GetStatus() (string, error)

GetStatus returns the current status of the unit

func (*Network) GetUnitName added in v0.3.0

func (n *Network) GetUnitName() string

GetUnitName returns the name of the unit

func (*Network) GetUnitType added in v0.3.0

func (n *Network) GetUnitType() string

GetUnitType returns the type of the unit

func (*Network) Restart added in v0.3.0

func (n *Network) Restart() error

Restart restarts the unit

func (*Network) Show added in v0.3.0

func (n *Network) Show() error

Show displays the unit configuration and status

func (*Network) Start added in v0.3.0

func (n *Network) Start() error

Start starts the unit

func (*Network) Stop added in v0.3.0

func (n *Network) Stop() error

Stop stops the unit

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

func NewProcessor

func NewProcessor(repo *git.Repository, unitRepo Repository) *Processor

func (*Processor) Process

func (p *Processor) Process(force bool) error

type QuadletUnit

type QuadletUnit struct {
	Name      string        `yaml:"name"`
	Type      string        `yaml:"type"`
	Systemd   SystemdConfig `yaml:"systemd"`
	Container Container     `yaml:"container,omitempty"`
	Volume    Volume        `yaml:"volume,omitempty"`
	Network   Network       `yaml:"network,omitempty"`
	Image     Image         `yaml:"image,omitempty"`
}

QuadletUnit represents the configuration for a Quadlet unit, which can include systemd, container, volume, network, pod, Kubernetes, image, and build settings.

func (*QuadletUnit) GetSystemdUnit added in v0.3.0

func (u *QuadletUnit) GetSystemdUnit() SystemdUnit

GetSystemdUnit returns the appropriate SystemdUnit implementation for this QuadletUnit

type Repository

type Repository interface {
	FindAll() ([]Unit, error)
	FindByUnitType(unitType string) ([]Unit, error)
	FindByID(id int64) (Unit, error)
	Create(unit *Unit) (int64, error)
	Delete(id int64) error
}

Repository defines the interface for unit data access operations

func NewUnitRepository

func NewUnitRepository(db *sql.DB) Repository

NewUnitRepository creates a new SQL-based unit repository

type SQLRepository added in v0.3.0

type SQLRepository struct {
	// contains filtered or unexported fields
}

SQLRepository implements UnitRepository interface with SQL database

func (*SQLRepository) Create added in v0.3.0

func (r *SQLRepository) Create(unit *Unit) (int64, error)

Create inserts or updates a unit in the database

func (*SQLRepository) Delete added in v0.3.0

func (r *SQLRepository) Delete(id int64) error

Delete removes a unit from the database

func (*SQLRepository) FindAll added in v0.3.0

func (r *SQLRepository) FindAll() ([]Unit, error)

FindAll retrieves all units from the database

func (*SQLRepository) FindByID added in v0.3.0

func (r *SQLRepository) FindByID(id int64) (Unit, error)

FindByID retrieves a single unit by ID

func (*SQLRepository) FindByUnitType added in v0.3.0

func (r *SQLRepository) FindByUnitType(unitType string) ([]Unit, error)

FindByUnitType retrieves units filtered by type

type Secret added in v0.3.0

type Secret struct {
	Name   string `yaml:"name"`
	Type   string `yaml:"type"`   // mount or env
	Target string `yaml:"target"` // defaults to secret name
	UID    int    `yaml:"uid"`    // defaults to 0, mount type only
	GID    int    `yaml:"gid"`    // defaults to 0, mount type only
	Mode   string `yaml:"mode"`   // defaults to 0444, mount type only
}

func (Secret) Validate added in v0.3.0

func (sc Secret) Validate() error

type SystemdConfig

type SystemdConfig struct {
	Description     string   `yaml:"description"`
	After           []string `yaml:"after"`
	Before          []string `yaml:"before"`
	Requires        []string `yaml:"requires"`
	Wants           []string `yaml:"wants"`
	Conflicts       []string `yaml:"conflicts"`
	RestartPolicy   string   `yaml:"restart_policy"`
	TimeoutStartSec int      `yaml:"timeout_start_sec"`
	Type            string   `yaml:"type"`
	RemainAfterExit bool     `yaml:"remain_after_exit"`
	WantedBy        []string `yaml:"wanted_by"`
}

SystemdConfig represents the configuration for a systemd unit. It includes settings such as the unit description, dependencies, restart policy, and other systemd-specific options.

type SystemdUnit added in v0.3.0

type SystemdUnit interface {
	// GetServiceName returns the full systemd service name
	GetServiceName() string

	// GetUnitType returns the type of the unit (container, volume, network, etc.)
	GetUnitType() string

	// GetUnitName returns the name of the unit
	GetUnitName() string

	// GetStatus returns the current status of the unit
	GetStatus() (string, error)

	// Start starts the unit
	Start() error

	// Stop stops the unit
	Stop() error

	// Restart restarts the unit
	Restart() error

	// Show displays the unit configuration and status
	Show() error
}

SystemdUnit defines the interface for managing systemd units

type Unit

type Unit struct {
	ID            int64     `db:"id"`
	Name          string    `db:"name"`
	Type          string    `db:"type"`
	CleanupPolicy string    `db:"cleanup_policy"`
	SHA1Hash      []byte    `db:"sha1_hash"`
	CreatedAt     time.Time `db:"created_at"`
}

Unit represents a record in the units table

type Volume added in v0.3.0

type Volume struct {
	ContainersConfModule []string `yaml:"containers_conf_module"`
	Copy                 bool     `yaml:"copy"`
	Device               string   `yaml:"device"`
	Driver               string   `yaml:"driver"`
	GlobalArgs           []string `yaml:"global_args"`
	Group                string   `yaml:"group"`
	Image                string   `yaml:"image"`
	Label                []string `yaml:"label"`
	Options              []string `yaml:"options"`
	PodmanArgs           []string `yaml:"podman_args"`
	Type                 string   `yaml:"type"`
	User                 string   `yaml:"user"`
	VolumeName           string   `yaml:"volume_name"`

	// Systemd unit properties
	Name     string
	UnitType string
}

Volume represents the configuration for a volume in a Quadlet unit.

func NewVolume added in v0.3.0

func NewVolume(name string) *Volume

NewVolume creates a new Volume with the given name

func (*Volume) GetServiceName added in v0.3.0

func (v *Volume) GetServiceName() string

GetServiceName returns the full systemd service name

func (*Volume) GetStatus added in v0.3.0

func (v *Volume) GetStatus() (string, error)

GetStatus returns the current status of the unit

func (*Volume) GetUnitName added in v0.3.0

func (v *Volume) GetUnitName() string

GetUnitName returns the name of the unit

func (*Volume) GetUnitType added in v0.3.0

func (v *Volume) GetUnitType() string

GetUnitType returns the type of the unit

func (*Volume) Restart added in v0.3.0

func (v *Volume) Restart() error

Restart restarts the unit

func (*Volume) Show added in v0.3.0

func (v *Volume) Show() error

Show displays the unit configuration and status

func (*Volume) Start added in v0.3.0

func (v *Volume) Start() error

Start starts the unit

func (*Volume) Stop added in v0.3.0

func (v *Volume) Stop() error

Stop stops the unit

Jump to

Keyboard shortcuts

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