Systemctl

package module
v0.0.0-...-3fe5e20 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

PkgGoDev

Systemctl

这个库旨在为 Go 开发人员提供符合习惯的 systemctl 绑定,以便更容易地使用 Go 语言编写系统工具。这个工具试图通过为 systemctl 提供结构化、经过彻底测试的包装器,来消除随意使用 shell 执行 systemctl 命令的猜测工作。

如果你的系统不是运行(或目标是另一个运行)systemctl,这个库对你来说可能没什么用处。

什么是 systemctl

systemctl 是一个命令行程序,它允许用户控制 systemd 系统和服务管理器。

systemctl 可以用来检查和控制 "systemd" 系统和服务管理器的状态。有关这个工具管理的基本概念和功能的介绍,请参阅 官方 systemctl 文档

当前支持的 systemctl 功能

  • systemctl daemon-reload
  • systemctl disable
  • systemctl enable
  • systemctl reenable
  • systemctl is-active
  • systemctl is-enabled
  • systemctl is-failed
  • systemctl show
  • systemctl start
  • systemctl status
  • systemctl stop
  • systemctl restart
  • systemctl mask
  • systemctl unmask

...

当前支持的辅助功能

  • 检查服务是否激活 IsActive:确定指定的服务是否处于激活状态。
  • 检查服务是否启用 IsEnabled:检查服务是否设置为在系统启动时自动启动。
  • 检查服务是否失败 IsFailed:检查服务是否启动失败。
  • 获取服务启动时间 GetStartTime:获取服务的启动时间。
  • 获取服务重启次数 GetUnitRestartCount:获取服务重启的次数。
  • 获取服务内存使用量 GetMemoryUsage:获取服务当前的内存使用量。
  • 获取主进程 PID GetMainPID:获取服务主进程的进程 ID。
  • 列出所有单元 GetAllUnits:获取所有 systemd 单元的列表及其状态和描述。
  • 列出所有已屏蔽单元 GetAllMaskedUnits:获取所有被屏蔽(不允许启动)的 systemd 单元列表。
  • 检查单元是否已屏蔽 IsMasked:检查指定单元是否被屏蔽。
  • 检查服务是否正在运行 IsRunning:检查服务是否正在运行。

...

有用的错误

所有函数都返回一个预定义的错误类型,强烈建议正确处理这些错误。

上下文支持

这个库的所有调用都支持 Go 的 context 功能。

安装

你可以通过以下命令来安装 Systemctl Go 库:

go get github.com/HJH0924/Systemctl

如何使用

要使用 Systemctl Go 库,请按照以下步骤操作:

  1. 导入库到你的 Go 项目中。
import "github.com/HJH0924/Systemctl"
  1. 使用库中的功能函数来执行系统服务管理任务。

例如,要检查服务是否激活,你可以使用 IsActive 函数:

package main

import (
	"context"
	"fmt"

	"github.com/HJH0924/Systemctl"
)

func main() {
	ctx := context.Background()
	systemctl := Systemctl.NewSystemctl()
	res := systemctl.Start(ctx, "testservice", Systemctl.Options{Mode: Systemctl.USER})
	active, err := Systemctl.IsActive(systemctl, ctx, "testservice", Systemctl.Options{Mode: Systemctl.USER})
	if err != nil {
		fmt.Println("检查服务状态出错:", err)
		return
	}
	fmt.Printf("testservice 是否处于活动状态?%v\n", active)
}

运行测试

运行测试用例之前,您需要在您的系统上安装 testservice.service

# 以 root 用户身份运行测试
sudo make install-root
# 以普通用户身份运行测试
sudo make install-user

为了全面测试这个库,您需要以root用户和普通用户身份运行测试,因为systemctl可能需要root权限来执行某些操作。以下是一些建议:

  1. 以root用户身份运行测试:某些测试可能需要root权限,例如启用或禁用服务。

    sudo su root # 切换 root 用户
    go test -run TestDaemonReload # 以 root 身份运行 TestDaemonReload 测试用例
    
  2. 以普通用户身份运行测试:其他测试应该以普通用户身份运行,以确保库在没有提升权限的情况下也能正常工作。

    go test -run TestDaemonReload
    

贡献

欢迎任何形式的贡献!如果你有任何问题、建议或想要提交代码,请随时创建 issue 或提交 pull request。

Documentation

Index

Constants

View Source
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"
	CPUShares                       string = "CPUShares"
	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"
	StartupCPUShares                string = "StartupCPUShares"
	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

View Source
var (
	// ErrNotInstalled
	// Make sure systemctl is in the PATH before calling again
	ErrNotInstalled = errors.New("systemctl is not in $PATH")
)

Functions

func GetAllMaskedUnits

func GetAllMaskedUnits(systemctl *Systemctl, ctx context.Context, opts Options) ([]string, error)

GetAllMaskedUnits retrieves a list of all masked systemd units.

func GetMainPID

func GetMainPID(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (int, error)

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 IsActive

func IsActive(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (bool, error)

IsActive checks if the specified systemd unit is active.

func IsEnabled

func IsEnabled(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (bool, error)

IsEnabled checks if the specified systemd unit is enabled to start on boot.

func IsFailed

func IsFailed(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (bool, error)

IsFailed checks if the specified systemd unit has failed to start.

func IsMasked

func IsMasked(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (bool, error)

IsMasked checks if the specified systemd unit is masked.

func IsRunning

func IsRunning(systemctl *Systemctl, ctx context.Context, unit string, opts Options) (bool, error)

IsRunning checks if the specified systemd service is currently running. https://unix.stackexchange.com/a/396633

func Show

func Show(systemctl *Systemctl, ctx context.Context, unit string, property string, opts Options) (string, error)

Show retrieves a specific property of a systemd unit.

Types

type Options

type Options struct {
	Mode UserMode
}

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

func (Self *Systemctl) Disable(ctx context.Context, unit string, opts Options) SystemctlResult

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

func (Self *Systemctl) Enable(ctx context.Context, unit string, opts Options) SystemctlResult

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

func (Self *Systemctl) IsActive(ctx context.Context, unit string, opts Options) SystemctlResult

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

func (Self *Systemctl) IsEnabled(ctx context.Context, unit string, opts Options) SystemctlResult

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

func (Self *Systemctl) IsFailed(ctx context.Context, unit string, opts Options) SystemctlResult

IsFailed Check whether any of the specified units are in a "failed" state.

func (*Systemctl) Mask

func (Self *Systemctl) Mask(ctx context.Context, unit string, opts Options) SystemctlResult

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

func (Self *Systemctl) ReEnable(ctx context.Context, unit string, opts Options) SystemctlResult

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

func (Self *Systemctl) ReStart(ctx context.Context, unit string, opts Options) SystemctlResult

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) Start

func (Self *Systemctl) Start(ctx context.Context, unit string, opts Options) SystemctlResult

Start (activate) a given unit

func (*Systemctl) Status

func (Self *Systemctl) Status(ctx context.Context, unit string, opts Options) SystemctlResult

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) Stop

func (Self *Systemctl) Stop(ctx context.Context, unit string, opts Options) SystemctlResult

Stop (deactivate) a given unit

func (*Systemctl) UnMask

func (Self *Systemctl) UnMask(ctx context.Context, unit string, opts Options) SystemctlResult

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

type SystemctlResult struct {
	Output   string
	Warnings string
	Code     int
	Err      error
}

func (*SystemctlResult) Print

func (Self *SystemctlResult) Print()

type Unit

type Unit struct {
	Name        string
	Load        string
	Active      string
	Sub         string
	Description string
}

func GetAllUnits

func GetAllUnits(systemctl *Systemctl, ctx context.Context, opts Options) ([]Unit, error)

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.

func (*Unit) Print

func (Self *Unit) Print()

type UserMode

type UserMode bool
const (
	ROOT UserMode = false
	USER UserMode = true
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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