Documentation ¶
Index ¶
- Variables
- type Client
- type CreateUnitFileOpt
- type CreateUnitFileRequest
- type GetUnitJournalRequest
- type GetUnitJournalResponse
- type Iniable
- type RunSystemctlCommandOpt
- func WithSystemctlCommandOptions(options string) RunSystemctlCommandOpt
- func WithSystemctlCommandPattern(pattern string) RunSystemctlCommandOpt
- func WithSystemctlCommandSubCommand(cmd SystemctlSubCommand) RunSystemctlCommandOpt
- func WithSystemctlCommandUnitName(unit string) RunSystemctlCommandOpt
- func WithSystemctlCommandUnitType(typ UnitType) RunSystemctlCommandOpt
- func WithSystemctlCommandUser() RunSystemctlCommandOpt
- type ServiceInfo
- type SystemctlCommandReq
- type SystemctlCommandRes
- type SystemctlStatusCode
- type SystemctlSubCommand
- type Unit
- type UnitProperties
- type UnitType
Constants ¶
This section is empty.
Variables ¶
var EnabledAndRunningProperties = UnitProperties{
"LoadState": "loaded",
"ActiveState": "active",
"SubState": "running",
"UnitFileState": "enabled",
}
EnabledAndRunningProperties are properties that a systemd service unit should have to be considered active and running.
var KnownServices = []string{"boundary", "consul", "vault"}
KnownServices are list of known HashiCorp services.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // CreateUnitFile creates a systemd unit file for the provided request CreateUnitFile(ctx context.Context, req *CreateUnitFileRequest) error // EnableService enables a systemd service with the provided unit name EnableService(ctx context.Context, unit string) error // GetUnitJournal gets the journal for a systemd unit GetUnitJournal(ctx context.Context, req *GetUnitJournalRequest) (remoteflight.GetLogsResponse, error) // ListServices gets the list of systemd services installed ListServices(ctx context.Context) ([]ServiceInfo, error) // RestartService restarts a systemd service with the provided unit name RestartService(ctx context.Context, unit string) error // RunSystemctlCommand runs a systemctl command for the provided request RunSystemctlCommand(ctx context.Context, req *SystemctlCommandReq) (*SystemctlCommandRes, error) // ShowProperties gets the properties of a matching unit or job ShowProperties(ctx context.Context, unit string) (UnitProperties, error) // StartService starts a systemd service with the provided unit name StartService(ctx context.Context, unit string) error // StopService stops a systemd service with the provided unit name StopService(ctx context.Context, unit string) error // ServiceStatus gets the service status for a systemd service with the provided unit name ServiceStatus(ctx context.Context, unit string) SystemctlStatusCode }
Client an interface for a sysetmd client.
type CreateUnitFileOpt ¶
type CreateUnitFileOpt func(*CreateUnitFileRequest) *CreateUnitFileRequest
CreateUnitFileOpt is a functional option for an systemd unit request.
func WithUnitChmod ¶
func WithUnitChmod(chmod string) CreateUnitFileOpt
WithUnitChmod sets systemd unit permissions.
func WithUnitChown ¶
func WithUnitChown(chown string) CreateUnitFileOpt
WithUnitChown sets systemd unit ownership.
func WithUnitFile ¶
func WithUnitFile(unit Iniable) CreateUnitFileOpt
WithUnitFile sets systemd unit to use.
func WithUnitUnitPath ¶
func WithUnitUnitPath(path string) CreateUnitFileOpt
WithUnitUnitPath sets the unit name.
type CreateUnitFileRequest ¶
CreateUnitFileRequest is a systemd unit file creator.
func NewCreateUnitFileRequest ¶
func NewCreateUnitFileRequest(opts ...CreateUnitFileOpt) *CreateUnitFileRequest
NewCreateUnitFileRequest takes functional options and returns a new systemd unit request.
type GetUnitJournalRequest ¶
type GetUnitJournalResponse ¶
func (*GetUnitJournalResponse) GetAppName ¶
func (s *GetUnitJournalResponse) GetAppName() string
GetAppName implements remoteflight.GetUnitJournalResponse.
func (*GetUnitJournalResponse) GetLogFileName ¶
func (s *GetUnitJournalResponse) GetLogFileName() string
func (*GetUnitJournalResponse) GetLogs ¶
func (s *GetUnitJournalResponse) GetLogs() []byte
type RunSystemctlCommandOpt ¶
type RunSystemctlCommandOpt func(*SystemctlCommandReq) *SystemctlCommandReq
RunSystemctlCommandOpt is a functional option for an systemd unit request.
func WithSystemctlCommandOptions ¶
func WithSystemctlCommandOptions(options string) RunSystemctlCommandOpt
WithSystemctlCommandOptions sets any optional options to pass in.
func WithSystemctlCommandPattern ¶
func WithSystemctlCommandPattern(pattern string) RunSystemctlCommandOpt
WithSystemctlCommandPattern sets any optional pattern to pass in.
func WithSystemctlCommandSubCommand ¶
func WithSystemctlCommandSubCommand(cmd SystemctlSubCommand) RunSystemctlCommandOpt
WithSystemctlCommandSubCommand sets the systemctl sub-command.
func WithSystemctlCommandUnitName ¶
func WithSystemctlCommandUnitName(unit string) RunSystemctlCommandOpt
WithSystemctlCommandUnitName sets the command unit name.
func WithSystemctlCommandUnitType ¶
func WithSystemctlCommandUnitType(typ UnitType) RunSystemctlCommandOpt
WithSystemctlCommandUnitType sets the command unit type.
func WithSystemctlCommandUser ¶
func WithSystemctlCommandUser() RunSystemctlCommandOpt
WithSystemctlCommandUser sets command to --user mode.
type ServiceInfo ¶
ServiceInfo is a list units of type service from systemctl command reference https://man7.org/linux/man-pages/man1/systemctl.1.html#COMMANDS
type SystemctlCommandReq ¶
type SystemctlCommandReq struct { User bool // enable user mode Name string // unit name Type UnitType // unit type SubCommand SystemctlSubCommand // systemctl command Pattern string // optional command pattern to pass as args Options string // optional command options to pass as args Env map[string]string // any environment variables that need to be set }
SystemctlCommandReq is a sysmtemctl command request.
func NewRunSystemctlCommand ¶
func NewRunSystemctlCommand(opts ...RunSystemctlCommandOpt) *SystemctlCommandReq
NewRunSystemctlCommand takes functional options and returns a new systemd command.
func (*SystemctlCommandReq) String ¶
func (c *SystemctlCommandReq) String() (string, error)
String returns the command request as a systemctl string.
type SystemctlCommandRes ¶
type SystemctlCommandRes struct { Stdout string Stderr string Status SystemctlStatusCode }
SystemctlCommandRes is the command response.
type SystemctlStatusCode ¶
type SystemctlStatusCode int
SystemctlStatusCode is a systemctl exit code. Systemctl attempts to use LSB exit codes, however, there are lots of corner cases which make certain codes unreliable and not all sub-commands adhere to these codes. As such, we should strive to interpret a units state by looking at its properties whenever possible
Further reading:
- https://www.freedesktop.org/software/systemd/man/systemctl.html#Exit%20status
- https://freedesktop.org/software/systemd/man/systemd.exec.html#Process%20Exit%20Codes
- https://bugs.freedesktop.org/show_bug.cgi?id=77507
const ( StatusOK SystemctlStatusCode = 0 StatusNotFailed SystemctlStatusCode = 1 StatusNotActive SystemctlStatusCode = 3 StatusNoSuchUnit SystemctlStatusCode = 4 StatusUnknown SystemctlStatusCode = 9 )
func (SystemctlStatusCode) String ¶
func (s SystemctlStatusCode) String() string
type SystemctlSubCommand ¶
type SystemctlSubCommand int
SystemctlSubCommand is the systemctl sub command to use.
const ( SystemctlSubCommandNotSet SystemctlSubCommand = iota SystemctlSubCommandDaemonReload SystemctlSubCommandEnable SystemctlSubCommandIsActive SystemctlSubCommandKill SystemctlSubCommandListUnits SystemctlSubCommandReload SystemctlSubCommandRestart SystemctlSubCommandShow SystemctlSubCommandStart SystemctlSubCommandStatus SystemctlSubCommandStop )
SystemctlSubCommands are the systemctl sub commands.
type Unit ¶
Unit is a map structure representing any systemd unit. The first keys represent stanzas and the values of each stanza is a map of filed names and values.
type UnitProperties ¶
UnitProperties are a key value map of unit properties.
func NewUnitProperties ¶
func NewUnitProperties() UnitProperties
NewUnitProperties returns a new NewUnitProperties.
func (UnitProperties) Find ¶
func (s UnitProperties) Find(names ...string) (UnitProperties, error)
Find takes one-or-more property names and returns a set of unit properties that match the names. Unless all properties are found an error will be returned.
func (UnitProperties) FindProperties ¶
func (s UnitProperties) FindProperties(in UnitProperties) (UnitProperties, error)
FindProperties is like Find() but instead of a list of values it derives the key name from those defined in the pass in UnitProperties. The values of properties in the given set are ignored.
func (UnitProperties) HasProperties ¶
func (s UnitProperties) HasProperties(in UnitProperties) bool
HasProperties determines whether the current unit properties contains all properties of another property set. This does not enfore exact comparison, only that the first set shares all from the second set.
func (UnitProperties) String ¶
func (s UnitProperties) String() string
type UnitType ¶
type UnitType int
UnitType is the systemd unit type to operate on.