unit

package
Version: v22.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: Apache-2.0 Imports: 8 Imported by: 37

Documentation

Index

Constants

View Source
const (
	// SYSTEMD_LINE_MAX mimics the maximum line length that systemd can use.
	// On typical systemd platforms (i.e. modern Linux), this will most
	// commonly be 2048, so let's use that as a sanity check.
	// Technically, we should probably pull this at runtime:
	//    SYSTEMD_LINE_MAX = int(C.sysconf(C.__SC_LINE_MAX))
	// but this would introduce an (unfortunate) dependency on cgo
	SYSTEMD_LINE_MAX = 2048

	// SYSTEMD_NEWLINE defines characters that systemd considers indicators
	// for a newline.
	SYSTEMD_NEWLINE = "\r\n"
)

Variables

View Source
var (
	// ErrLineTooLong gets returned when a line is too long for systemd to handle.
	ErrLineTooLong = fmt.Errorf("line too long (max %d bytes)", SYSTEMD_LINE_MAX)
)

Functions

func AllMatch

func AllMatch(u1 []*UnitOption, u2 []*UnitOption) bool

AllMatch compares two slices of UnitOptions and returns true if they are identical.

func Serialize

func Serialize(opts []*UnitOption) io.Reader

Serialize encodes all of the given UnitOption objects into a unit file. When serialized the options are sorted in their supplied order but grouped by section.

func SerializeSections added in v22.1.0

func SerializeSections(sections []*UnitSection) io.Reader

SerializeSections will serializes the unit file from the given UnitSections.

func UnitNameEscape

func UnitNameEscape(unescaped string) string

UnitNameEscape escapes a string as `systemd-escape` would

func UnitNamePathEscape

func UnitNamePathEscape(unescaped string) string

UnitNamePathEscape escapes a string as `systemd-escape --path` would

func UnitNamePathUnescape

func UnitNamePathUnescape(escaped string) string

UnitNamePathUnescape unescapes a string as `systemd-escape --path --unescape` would

func UnitNameUnescape

func UnitNameUnescape(escaped string) string

UnitNameUnescape unescapes a string as `systemd-escape --unescape` would

Types

type UnitEntry added in v22.1.0

type UnitEntry struct {
	Name  string
	Value string
}

UnitEntry is a single line entry in a Unit file.

func (*UnitEntry) String added in v22.1.0

func (u *UnitEntry) String() string

String implements the stringify interface for UnitEntry

type UnitOption

type UnitOption struct {
	Section string
	Name    string
	Value   string
}

UnitOption represents an option in a systemd unit file.

func Deserialize

func Deserialize(f io.Reader) (opts []*UnitOption, err error)

Deserialize parses a systemd unit file into a list of UnitOptions. Note: this function is deprecated in favor of DeserializeOptions and will be removed at a future date.

func DeserializeOptions added in v22.1.0

func DeserializeOptions(f io.Reader) (opts []*UnitOption, err error)

DeserializeOptions parses a systemd unit file into a list of UnitOptions

func NewUnitOption

func NewUnitOption(section, name, value string) *UnitOption

NewUnitOption returns a new UnitOption instance with pre-set values.

func (*UnitOption) Match

func (uo *UnitOption) Match(other *UnitOption) bool

Match compares two UnitOptions and returns true if they are identical.

func (*UnitOption) String

func (uo *UnitOption) String() string

type UnitSection added in v22.1.0

type UnitSection struct {
	Section string
	Entries []*UnitEntry
}

UnitSection is a section in a Unit file. The section name and a list of entries in that section.

func DeserializeSections added in v22.1.0

func DeserializeSections(f io.Reader) ([]*UnitSection, error)

DeserializeSections deserializes into a list of UnitSections.

func (*UnitSection) String added in v22.1.0

func (s *UnitSection) String() string

String implements the stringify interface for UnitSection

Jump to

Keyboard shortcuts

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