systemd

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package systemd uses the native systemctl/journalctl commands to interact with the systemd and journald services.

Index

Constants

View Source
const (
	Emergency     = Priority("0")
	Alert         = Priority("1")
	Critical      = Priority("2")
	Error         = Priority("3")
	Warning       = Priority("4")
	Notice        = Priority("5")
	Informational = Priority("6")
	Debug         = Priority("7")
)

Priority levels

View Source
const (
	// Enabled is a state reported by systemctl
	Enabled = UnitFileState("enabled")

	// Disabled is a state reported by systemctl
	Disabled = UnitFileState("disabled")

	// Active is a state reported by systemctl
	Active = ActiveState("active")

	// Inactive is a state reported by systemctl
	Inactive = ActiveState("inactive")

	// Running is a substate reported by systemctl
	Running = SubState("running")

	// Dead is a substate reported by systemctl
	Dead = SubState("dead")
)

Variables

This section is empty.

Functions

func UnitName

func UnitName(service string) string

UnitName converts a service name into a unit name in the systemd lingo ([name].service)

Types

type ActiveState

type ActiveState string

ActiveState is state type for Systemctl

type Entry

type Entry struct {
	Cursor        string      `json:"__CURSOR"`                    // The __CURSOR field
	Timestamp     int64       `json:"__REALTIME_TIMESTAMP,string"` // The __REALTIME__TIMESTAMP field (microseconds since epoch)
	Message       string      `json:"-"`                           // The string representation of the message source.
	MessageSource interface{} `json:"MESSAGE"`                     // The MESSAGE field. This might be an array of bytes *or* a string
	Unit          string      `json:"_SYSTEMD_UNIT"`               // The _SYSTEMD_UNIT field
	Priority      Priority    `json:"PRIORITY"`                    // The PRIORITY field
	UnitResult    string      `json:"UNIT_RESULT"`                 // The UNIT_RESULT field. This is set if the service has terminated for some reason. It is empty otherwise
	Valid         bool        `json:"-"`                           // Valid JSON when decoding
	SourceData    string      `json:"-"`                           // The source JSON. This might be invalid.
}

Entry is a single entry from journald

func (*Entry) IsEmpty

func (e *Entry) IsEmpty() bool

IsEmpty returns true if this is an empty entry

func (Entry) String

func (e Entry) String() string

String pretty-prints the entry

type Journalctl

type Journalctl interface {
	// Entries returns the last entry in the journal. If there is no entries
	// an empty entry will be returned
	LastEntry(unit string) (Entry, error)

	// EntriesAfter returns entries after the specified cursor position. The
	// newest entry is returned first. If the cursor parameter is empty the
	// last 100 entries are returned.
	EntriesAfter(unit string, cursor string) ([]Entry, error)
}

Journalctl interacts with the native journalctl installation to pull logs from the systemd-journald

func NewJournalctl

func NewJournalctl() Journalctl

NewJournalctl returns a dummy journalctl

type Priority

type Priority string

Priority is the level of the journald entries (0-7)

type SubState

type SubState string

SubState is state type for Systemctl

type Systemctl

type Systemctl interface {
	// State returns unit file, active and substate for the unit.
	State(unitName string) (UnitFileState, ActiveState, SubState, error)

	// Restart call systemctl restart <unit> -- if there's an error the exit
	// code will hint at what the issue is (see systemctl(1) man page for exit codes)
	Restart(unitName string) error

	// Stop stops the unit
	Stop(unitName string) error
}

Systemctl interacts with the native systemcl command

func NewSystemctl

func NewSystemctl() Systemctl

NewSystemctl returns a systemctl implementation

type UnitFileState

type UnitFileState string

UnitFileState is state type for Systemctl

Jump to

Keyboard shortcuts

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