Documentation ¶
Index ¶
- Constants
- func Available() error
- func EscapeUnitNamePath(in string) string
- func IsTimeout(err error) bool
- func MockJournalctl(f func(svcs []string, n int, follow bool) (io.ReadCloser, error)) func()
- func MockStopDelays(checkDelay, notifyDelay time.Duration) func()
- func MockSystemctl(f func(args ...string) ([]byte, error)) func()
- func MockSystemdSysctl(f func(args ...string) error) func()
- func MountUnitPath(baseDir string) string
- func NewJournalStreamFile(identifier string, priority syslog.Priority, levelPrefix bool) (*os.File, error)
- func SdNotify(notifyState string) error
- func Sysctl(prefixes []string) error
- func Version() (int, error)
- type Error
- type InstanceMode
- type Log
- type Systemd
- type Timeout
- type UnitStatus
Constants ¶
const ( // the default target for systemd units that we generate ServicesTarget = "multi-user.target" // the target prerequisite for systemd units we generate PrerequisiteTarget = "network.target" // the default target for systemd socket units that we generate SocketsTarget = "sockets.target" // the default target for systemd timer units that we generate TimersTarget = "timers.target" // the target for systemd user session units that we generate UserServicesTarget = "default.target" )
Variables ¶
This section is empty.
Functions ¶
func EscapeUnitNamePath ¶
EscapeUnitNamePath works like systemd-escape --path FIXME: we could use github.com/coreos/go-systemd/unit/escape.go
and EscapePath from it. But thats not in the archive and it won't work with go1.3
func MockJournalctl ¶
func MockStopDelays ¶
MockStopDelays is used from tests so that Stop can be less forgiving there.
func MockSystemctl ¶
MockSystemctl is called from the commands to actually call out to systemctl. It's exported so it can be overridden by testing.
func MockSystemdSysctl ¶
MockSystemdSysctl lets mock and intercept calls to systemd-sysctl from the package.
func MountUnitPath ¶
MountUnitPath returns the path of a {,auto}mount unit
func NewJournalStreamFile ¶
func NewJournalStreamFile(identifier string, priority syslog.Priority, levelPrefix bool) (*os.File, error)
NewJournalStreamFile creates log stream file descriptor to the journal. The semantics is identical to that of sd_journal_stream_fd(3) call.
func SdNotify ¶
SdNotify sends the given state string notification to systemd.
inspired by libsystemd/sd-daemon/sd-daemon.c from the systemd source
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is returned if the systemd action failed
type InstanceMode ¶
type InstanceMode int
InstanceMode determines which instance of systemd to control.
SystemMode refers to the system instance (i.e. pid 1). UserMode refers to the instance launched to manage the user's desktop session. GlobalUserMode controls configuration respected by all user instances on the system.
As GlobalUserMode does not refer to a single instance of systemd, some operations are not supported such as starting and stopping daemons.
const ( SystemMode InstanceMode = iota UserMode GlobalUserMode )
type Log ¶
type Log map[string]*json.RawMessage
A Log is a single entry in the systemd journal. In almost all cases, the strings map to a single string value, but as per the manpage for journalctl, under the json format,
Journal entries permit non-unique fields within the same log entry. JSON does not allow non-unique fields within objects. Due to this, if a non-unique field is encountered a JSON array is used as field value, listing all field values as elements.
and this snippet as well,
Fields containing non-printable or non-UTF8 bytes are encoded as arrays containing the raw bytes individually formatted as unsigned numbers.
as such, we sometimes get array values which need to be handled differently, so we manually try to decode the json for each message into different types.
type Systemd ¶
type Systemd interface { // DaemonReload reloads systemd's configuration. DaemonReload() error // DaemonRexec reexecutes systemd's system manager, should be // only necessary to apply manager's configuration like // watchdog. DaemonReexec() error // Enable the given service. Enable(service string) error // Disable the given service. Disable(service string) error // Start the given service or services. Start(service ...string) error // StartNoBlock starts the given service or services non-blocking. StartNoBlock(service ...string) error // Stop the given service, and wait until it has stopped. Stop(service string, timeout time.Duration) error // Kill all processes of the unit with the given signal. Kill(service, signal, who string) error // Restart the service, waiting for it to stop before starting it again. Restart(service string, timeout time.Duration) error // Reload or restart the service via 'systemctl reload-or-restart' ReloadOrRestart(service string) error // RestartAll restarts the given service using systemctl restart --all RestartAll(service string) error // Status fetches the status of given units. Statuses are // returned in the same order as unit names passed in // argument. Status(units ...string) ([]*UnitStatus, error) // InactiveEnterTimestamp returns the time that the given unit entered the // inactive state as defined by the systemd docs. Specifically, this time is // the most recent time in which the unit transitioned from deactivating // ("Stopping") to dead ("Stopped"). It may be the zero time if this has // never happened during the current boot, since this property is only // tracked during the current boot. It specifically does not return a time // that is monotonic, so the time returned here may be subject to bugs if // there was a discontinuous time jump on the system before or during the // unit's transition to inactive. // TODO: incorporate this result into Status instead? InactiveEnterTimestamp(unit string) (time.Time, error) // IsEnabled checks whether the given service is enabled. IsEnabled(service string) (bool, error) // IsActive checks whether the given service is Active IsActive(service string) (bool, error) // LogReader returns a reader for the given services' log. LogReader(services []string, n int, follow bool) (io.ReadCloser, error) // AddMountUnitFile adds/enables/starts a mount unit. AddMountUnitFile(name, revision, what, where, fstype string) (string, error) // RemoveMountUnitFile unmounts/stops/disables/removes a mount unit. RemoveMountUnitFile(baseDir string) error // Mask the given service. Mask(service string) error // Unmask the given service. Unmask(service string) error // Mount requests a mount of what under where with options. Mount(what, where string, options ...string) error // Umount requests a mount from what or at where to be unmounted. Umount(whatOrWhere string) error // CurrentMemoryUsage returns the current memory usage for the specified // unit. CurrentMemoryUsage(unit string) (quantity.Size, error) // CurrentTasksCount returns the number of tasks (processes, threads, kernel // threads if enabled, etc) part of the unit, which can be a service or a // slice. CurrentTasksCount(unit string) (uint64, error) }
Systemd exposes a minimal interface to manage systemd via the systemctl command.
func New ¶
func New(mode InstanceMode, rep reporter) Systemd
New returns a Systemd that uses the default root directory and omits --root argument when executing systemctl.
func NewEmulationMode ¶
NewEmulationMode returns a Systemd that runs in emulation mode where systemd is not really called, but instead its functions are emulated by other means.
func NewUnderRoot ¶
func NewUnderRoot(rootDir string, mode InstanceMode, rep reporter) Systemd
NewUnderRoot returns a Systemd that operates on the given rootdir.