Documentation ¶
Index ¶
- Constants
- Variables
- func GetAllMaskedUnits(systemctl *Systemctl, ctx context.Context, opts Options) ([]string, error)
- func GetMainPID(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (int, error)
- func GetMemoryUsage(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (int, error)
- func GetStartTime(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (time.Time, error)
- func GetUnitRestartCount(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (int, error)
- func IsActive(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (bool, error)
- func IsEnabled(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (bool, error)
- func IsFailed(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (bool, error)
- func IsMasked(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (bool, error)
- func IsRunning(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (bool, error)
- func Show(systemctl *Systemctl, ctx context.Context, unit string, property string, ...) (string, error)
- type Options
- type Systemctl
- func (Self *Systemctl) DaemonReload(ctx context.Context, opts Options) SystemctlResult
- func (Self *Systemctl) Disable(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) Enable(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) Execute(ctx context.Context, args []string) SystemctlResult
- func (Self *Systemctl) IsActive(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) IsEnabled(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) IsFailed(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) Mask(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) ReEnable(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) ReStart(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) Show(ctx context.Context, unit string, property string, opts Options) SystemctlResult
- func (Self *Systemctl) Start(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) Status(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) Stop(ctx context.Context, unit string, opts Options) SystemctlResult
- func (Self *Systemctl) UnMask(ctx context.Context, unit string, opts Options) SystemctlResult
- type SystemctlResult
- type Unit
- type UserMode
Constants ¶
const ( ActiveEnterTimestamp string = "ActiveEnterTimestamp" ActiveEnterTimestampMonotonic string = "ActiveEnterTimestampMonotonic" ActiveExitTimestampMonotonic string = "ActiveExitTimestampMonotonic" ActiveState string = "ActiveState" After string = "After" AllowIsolate string = "AllowIsolate" AssertResult string = "AssertResult" AssertTimestamp string = "AssertTimestamp" AssertTimestampMonotonic string = "AssertTimestampMonotonic" Before string = "Before" BlockIOAccounting string = "BlockIOAccounting" BlockIOWeight string = "BlockIOWeight" CPUAccounting string = "CPUAccounting" CPUAffinityFromNUMA string = "CPUAffinityFromNUMA" CPUQuotaPerSecUSec string = "CPUQuotaPerSecUSec" CPUQuotaPeriodUSec string = "CPUQuotaPeriodUSec" CPUSchedulingPolicy string = "CPUSchedulingPolicy" CPUSchedulingPriority string = "CPUSchedulingPriority" CPUSchedulingResetOnFork string = "CPUSchedulingResetOnFork" CPUUsageNSec string = "CPUUsageNSec" CPUWeight string = "CPUWeight" CacheDirectoryMode string = "CacheDirectoryMode" CanFreeze string = "CanFreeze" CanIsolate string = "CanIsolate" CanReload string = "CanReload" CanStart string = "CanStart" CanStop string = "CanStop" CapabilityBoundingSet string = "CapabilityBoundingSet" CleanResult string = "CleanResult" CollectMode string = "CollectMode" ConditionResult string = "ConditionResult" ConditionTimestamp string = "ConditionTimestamp" ConditionTimestampMonotonic string = "ConditionTimestampMonotonic" ConfigurationDirectoryMode string = "ConfigurationDirectoryMode" Conflicts string = "Conflicts" ControlGroup string = "ControlGroup" ControlPID string = "ControlPID" CoredumpFilter string = "CoredumpFilter" DefaultDependencies string = "DefaultDependencies" DefaultMemoryLow string = "DefaultMemoryLow" DefaultMemoryMin string = "DefaultMemoryMin" Delegate string = "Delegate" Description string = "Description" DevicePolicy string = "DevicePolicy" DynamicUser string = "DynamicUser" EffectiveCPUs string = "EffectiveCPUs" EffectiveMemoryNodes string = "EffectiveMemoryNodes" ExecMainCode string = "ExecMainCode" ExecMainExitTimestampMonotonic string = "ExecMainExitTimestampMonotonic" ExecMainPID string = "ExecMainPID" ExecMainStartTimestamp string = "ExecMainStartTimestamp" ExecMainStartTimestampMonotonic string = "ExecMainStartTimestampMonotonic" ExecMainStatus string = "ExecMainStatus" ExecReload string = "ExecReload" ExecReloadEx string = "ExecReloadEx" ExecStart string = "ExecStart" ExecStartEx string = "ExecStartEx" FailureAction string = "FailureAction" FileDescriptorStoreMax string = "FileDescriptorStoreMax" FinalKillSignal string = "FinalKillSignal" FragmentPath string = "FragmentPath" FreezerState string = "FreezerState" GID string = "GID" GuessMainPID string = "GuessMainPID" IOAccounting string = "IOAccounting" IOReadBytes string = "IOReadBytes" IOReadOperations string = "IOReadOperations" IOSchedulingClass string = "IOSchedulingClass" IOSchedulingPriority string = "IOSchedulingPriority" IOWeight string = "IOWeight" IOWriteBytes string = "IOWriteBytes" IOWriteOperations string = "IOWriteOperations" IPAccounting string = "IPAccounting" IPEgressBytes string = "IPEgressBytes" IPEgressPackets string = "IPEgressPackets" IPIngressBytes string = "IPIngressBytes" IPIngressPackets string = "IPIngressPackets" Id string = "Id" IgnoreOnIsolate string = "IgnoreOnIsolate" IgnoreSIGPIPE string = "IgnoreSIGPIPE" InactiveEnterTimestampMonotonic string = "InactiveEnterTimestampMonotonic" InactiveExitTimestamp string = "InactiveExitTimestamp" InactiveExitTimestampMonotonic string = "InactiveExitTimestampMonotonic" InvocationID string = "InvocationID" JobRunningTimeoutUSec string = "JobRunningTimeoutUSec" JobTimeoutAction string = "JobTimeoutAction" JobTimeoutUSec string = "JobTimeoutUSec" KeyringMode string = "KeyringMode" KillMode string = "KillMode" KillSignal string = "KillSignal" LimitAS string = "LimitAS" LimitASSoft string = "LimitASSoft" LimitCORE string = "LimitCORE" LimitCORESoft string = "LimitCORESoft" LimitCPU string = "LimitCPU" LimitCPUSoft string = "LimitCPUSoft" LimitDATA string = "LimitDATA" LimitDATASoft string = "LimitDATASoft" LimitFSIZE string = "LimitFSIZE" LimitFSIZESoft string = "LimitFSIZESoft" LimitLOCKS string = "LimitLOCKS" LimitLOCKSSoft string = "LimitLOCKSSoft" LimitMEMLOCK string = "LimitMEMLOCK" LimitMEMLOCKSoft string = "LimitMEMLOCKSoft" LimitMSGQUEUE string = "LimitMSGQUEUE" LimitMSGQUEUESoft string = "LimitMSGQUEUESoft" LimitNICE string = "LimitNICE" LimitNICESoft string = "LimitNICESoft" LimitNOFILE string = "LimitNOFILE" LimitNOFILESoft string = "LimitNOFILESoft" LimitNPROC string = "LimitNPROC" LimitNPROCSoft string = "LimitNPROCSoft" LimitRSS string = "LimitRSS" LimitRSSSoft string = "LimitRSSSoft" LimitRTPRIO string = "LimitRTPRIO" LimitRTPRIOSoft string = "LimitRTPRIOSoft" LimitRTTIME string = "LimitRTTIME" LimitRTTIMESoft string = "LimitRTTIMESoft" LimitSIGPENDING string = "LimitSIGPENDING" LimitSIGPENDINGSoft string = "LimitSIGPENDINGSoft" LimitSTACK string = "LimitSTACK" LimitSTACKSoft string = "LimitSTACKSoft" LoadState string = "LoadState" LockPersonality string = "LockPersonality" LogLevelMax string = "LogLevelMax" LogRateLimitBurst string = "LogRateLimitBurst" LogRateLimitIntervalUSec string = "LogRateLimitIntervalUSec" LogsDirectoryMode string = "LogsDirectoryMode" MainPID string = "MainPID" ManagedOOMMemoryPressure string = "ManagedOOMMemoryPressure" ManagedOOMMemoryPressureLimit string = "ManagedOOMMemoryPressureLimit" ManagedOOMPreference string = "ManagedOOMPreference" ManagedOOMSwap string = "ManagedOOMSwap" MemoryAccounting string = "MemoryAccounting" MemoryCurrent string = "MemoryCurrent" MemoryDenyWriteExecute string = "MemoryDenyWriteExecute" MemoryHigh string = "MemoryHigh" MemoryLimit string = "MemoryLimit" MemoryLow string = "MemoryLow" MemoryMax string = "MemoryMax" MemoryMin string = "MemoryMin" MemorySwapMax string = "MemorySwapMax" MountAPIVFS string = "MountAPIVFS" NFileDescriptorStore string = "NFileDescriptorStore" NRestarts string = "NRestarts" NUMAPolicy string = "NUMAPolicy" Names string = "Names" NeedDaemonReload string = "NeedDaemonReload" Nice string = "Nice" NoNewPrivileges string = "NoNewPrivileges" NonBlocking string = "NonBlocking" NotifyAccess string = "NotifyAccess" OOMPolicy string = "OOMPolicy" OOMScoreAdjust string = "OOMScoreAdjust" OnFailureJobMode string = "OnFailureJobMode" PIDFile string = "PIDFile" Perpetual string = "Perpetual" PrivateDevices string = "PrivateDevices" PrivateIPC string = "PrivateIPC" PrivateMounts string = "PrivateMounts" PrivateNetwork string = "PrivateNetwork" PrivateTmp string = "PrivateTmp" PrivateUsers string = "PrivateUsers" ProcSubset string = "ProcSubset" ProtectClock string = "ProtectClock" ProtectControlGroups string = "ProtectControlGroups" ProtectHome string = "ProtectHome" ProtectHostname string = "ProtectHostname" ProtectKernelLogs string = "ProtectKernelLogs" ProtectKernelModules string = "ProtectKernelModules" ProtectKernelTunables string = "ProtectKernelTunables" ProtectProc string = "ProtectProc" ProtectSystem string = "ProtectSystem" RefuseManualStart string = "RefuseManualStart" RefuseManualStop string = "RefuseManualStop" ReloadResult string = "ReloadResult" RemainAfterExit string = "RemainAfterExit" RemoveIPC string = "RemoveIPC" Requires string = "Requires" Restart string = "Restart" RestartKillSignal string = "RestartKillSignal" RestartUSec string = "RestartUSec" RestrictNamespaces string = "RestrictNamespaces" RestrictRealtime string = "RestrictRealtime" RestrictSUIDSGID string = "RestrictSUIDSGID" Result string = "Result" RootDirectoryStartOnly string = "RootDirectoryStartOnly" RuntimeDirectoryMode string = "RuntimeDirectoryMode" RuntimeDirectoryPreserve string = "RuntimeDirectoryPreserve" RuntimeMaxUSec string = "RuntimeMaxUSec" SameProcessGroup string = "SameProcessGroup" SecureBits string = "SecureBits" SendSIGHUP string = "SendSIGHUP" SendSIGKILL string = "SendSIGKILL" Slice string = "Slice" StandardError string = "StandardError" StandardInput string = "StandardInput" StandardOutput string = "StandardOutput" StartLimitAction string = "StartLimitAction" StartLimitBurst string = "StartLimitBurst" StartLimitIntervalUSec string = "StartLimitIntervalUSec" StartupBlockIOWeight string = "StartupBlockIOWeight" StartupCPUWeight string = "StartupCPUWeight" StartupIOWeight string = "StartupIOWeight" StateChangeTimestamp string = "StateChangeTimestamp" StateChangeTimestampMonotonic string = "StateChangeTimestampMonotonic" StateDirectoryMode string = "StateDirectoryMode" StatusErrno string = "StatusErrno" StopWhenUnneeded string = "StopWhenUnneeded" SubState string = "SubState" SuccessAction string = "SuccessAction" SyslogFacility string = "SyslogFacility" SyslogLevel string = "SyslogLevel" SyslogLevelPrefix string = "SyslogLevelPrefix" SyslogPriority string = "SyslogPriority" SystemCallErrorNumber string = "SystemCallErrorNumber" TTYReset string = "TTYReset" TTYVHangup string = "TTYVHangup" TTYVTDisallocate string = "TTYVTDisallocate" TasksAccounting string = "TasksAccounting" TasksCurrent string = "TasksCurrent" TasksMax string = "TasksMax" TimeoutAbortUSec string = "TimeoutAbortUSec" TimeoutCleanUSec string = "TimeoutCleanUSec" TimeoutStartFailureMode string = "TimeoutStartFailureMode" TimeoutStartUSec string = "TimeoutStartUSec" TimeoutStopFailureMode string = "TimeoutStopFailureMode" TimeoutStopUSec string = "TimeoutStopUSec" TimerSlackNSec string = "TimerSlackNSec" Transient string = "Transient" Type string = "Type" UID string = "UID" UMask string = "UMask" UnitFilePreset string = "UnitFilePreset" UnitFileState string = "UnitFileState" UtmpMode string = "UtmpMode" WantedBy string = "WantedBy" WatchdogSignal string = "WatchdogSignal" WatchdogTimestampMonotonic string = "WatchdogTimestampMonotonic" WatchdogUSec string = "WatchdogUSec" )
Variables ¶
var ( // ErrNotInstalled // Make sure systemctl is in the PATH before calling again ErrNotInstalled = errors.New("systemctl is not in $PATH") )
Functions ¶
func GetAllMaskedUnits ¶
GetAllMaskedUnits retrieves a list of all masked systemd units.
func GetMainPID ¶
GetMainPID Get the PID of the main process (`systemctl show [unit] --property MainPID`) as an int
func GetMemoryUsage ¶
func GetMemoryUsage(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (int, error)
GetMemoryUsage Get current memory in bytes (`systemctl show [unit] --property MemoryCurrent`) as an int
func GetStartTime ¶
func GetStartTime(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (time.Time, error)
GetStartTime Get start time of a service (`systemctl show [unit] --property ExecMainStartTimestamp`) as a `Time` type
func GetUnitRestartCount ¶
func GetUnitRestartCount(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (int, error)
GetUnitRestartCount Get the number of times a unit restarted (`systemctl show [unit] --property NRestarts`) as an int
func IsRunning ¶
IsRunning checks if the specified systemd service is currently running. https://unix.stackexchange.com/a/396633
Types ¶
type Systemctl ¶
type Systemctl struct {
// contains filtered or unexported fields
}
func NewSystemctl ¶
func NewSystemctl() *Systemctl
func (*Systemctl) DaemonReload ¶
func (Self *Systemctl) DaemonReload(ctx context.Context, opts Options) SystemctlResult
DaemonReload Reload the systemd manager configuration.
This will rerun all generators (see systemd.generator(7)), reload all unit files, and recreate the entire dependency tree. While the daemon is being reloaded, all sockets systemd listens on behalf of user configuration will stay accessible.
func (*Systemctl) Disable ¶
Disable Disables one or more units.
This removes all symlinks to the unit files backing the specified units from the unit configuration directory, and hence undoes any changes made by enable or link.
func (*Systemctl) Enable ¶
Enable one or more units or unit instances.
This will create a set of symlinks, as encoded in the [Install] sections of the indicated unit files. After the symlinks have been created, the system manager configuration is reloaded (in a way equivalent to daemon-reload), in order to ensure the changes are taken into account immediately.
func (*Systemctl) Execute ¶
func (Self *Systemctl) Execute(ctx context.Context, args []string) SystemctlResult
func (*Systemctl) IsActive ¶
IsActive Check whether any of the specified units are active (i.e. running).
Returns true if the unit is active, false if inactive or failed. Also returns false in an error case.
func (*Systemctl) IsEnabled ¶
IsEnabled Checks whether any of the specified unit files are enabled (as with enable).
Returns true if the unit is enabled, aliased, static, indirect, generated or transient.
Returns false if disabled. Also returns an error if linked, masked, or bad.
See https://www.freedesktop.org/software/systemd/man/systemctl.html#is-enabled%20UNIT%E2%80%A6 for more information
func (*Systemctl) IsFailed ¶
IsFailed Check whether any of the specified units are in a "failed" state.
func (*Systemctl) Mask ¶
Mask one or more units, as specified on the command line. This will link these unit files to /dev/null, making it impossible to start them.
Notably, Mask may return ErrDoesNotExist if a unit doesn't exist, but it will continue masking anyway. Calling Mask on a non-existing masked unit does not return an error. Similarly, see Unmask.
func (*Systemctl) ReEnable ¶
ReEnable Reenables one or more units.
This removes all symlinks to the unit files backing the specified units from the unit configuration directory, then recreates the symlink to the unit again, atomically. Can be used to change the symlink target.
func (*Systemctl) ReStart ¶
ReStart Stop and then start one or more units specified on the command line. If the units are not running yet, they will be started.
func (*Systemctl) Show ¶
func (Self *Systemctl) Show(ctx context.Context, unit string, property string, opts Options) SystemctlResult
Show a selected property of a unit. Accepted properties are predefined in the properties subpackage to guarantee properties are valid and assist code-completion.
func (*Systemctl) Status ¶
Status Get back the status string which would be returned by running `systemctl status [unit]`.
Generally, it makes more sense to programatically retrieve the properties using Show, but this command is provided for the sake of completeness
func (*Systemctl) UnMask ¶
UnMask one or more unit files, as specified on the command line. This will undo the effect of Mask.
In line with systemd, Unmask will return ErrDoesNotExist if the unit doesn't exist, but only if it's not already masked. If the unit doesn't exist but it's masked anyway, no error will be returned. Gross, I know. Take it up with Poettering.
type SystemctlResult ¶
func (*SystemctlResult) Print ¶
func (Self *SystemctlResult) Print()
type Unit ¶
func GetAllUnits ¶
GetAllUnits retrieves a list of all systemd units with their statuses and descriptions. It executes the `systemctl list-units` command with various options to get detailed information.