Documentation
¶
Overview ¶
Package utilexec provides simple command execution helpers for running commands on the host and inside nspawn machines with slog-based logging.
Index ¶
- func Azcmagent() func(context.Context) *exec.Cmd
- func Bash() func(context.Context) *exec.Cmd
- func Curl() func(context.Context) *exec.Cmd
- func DisableService(ctx context.Context, logger *slog.Logger, serviceName string) error
- func Dpkg() func(context.Context) *exec.Cmd
- func IsServiceActive(ctx context.Context, logger *slog.Logger, serviceName string) bool
- func MachineRun(ctx context.Context, logger *slog.Logger, machine string, args ...string) (string, error)
- func OutputCmd(ctx context.Context, logger *slog.Logger, name string, args ...string) (string, error)
- func OutputCmdAt(ctx context.Context, logger *slog.Logger, stderrLevel slog.Level, name string, ...) (string, error)
- func Pgrep() func(context.Context) *exec.Cmd
- func ReloadSystemd(ctx context.Context, logger *slog.Logger) error
- func RemoveAllIfExists(path string) error
- func RemoveFileIfExists(path string) error
- func RunCmd(ctx context.Context, logger *slog.Logger, ...) error
- func RunCmdAt(ctx context.Context, logger *slog.Logger, stderrLevel slog.Level, ...) error
- func ServiceExists(ctx context.Context, logger *slog.Logger, serviceName string) bool
- func StopService(ctx context.Context, logger *slog.Logger, serviceName string) error
- func Systemctl() func(context.Context) *exec.Cmd
- func Wget() func(context.Context) *exec.Cmd
- type Interface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisableService ¶
DisableService disables a systemd service.
func IsServiceActive ¶
IsServiceActive checks whether a systemd service is active.
func MachineRun ¶
func MachineRun(ctx context.Context, logger *slog.Logger, machine string, args ...string) (string, error)
MachineRun executes a command inside the named nspawn machine using systemd-run --machine=<machine> --pipe --wait and returns stdout.
func OutputCmd ¶
func OutputCmd(ctx context.Context, logger *slog.Logger, name string, args ...string) (string, error)
OutputCmd runs the command specified by name and args, and returns the captured stdout as a string. Stderr is logged at Info level.
func OutputCmdAt ¶
func OutputCmdAt(ctx context.Context, logger *slog.Logger, stderrLevel slog.Level, name string, args ...string) (string, error)
OutputCmdAt is like OutputCmd but streams stderr at stderrLevel.
func ReloadSystemd ¶
ReloadSystemd reloads systemd daemon configuration.
func RemoveAllIfExists ¶
RemoveAllIfExists removes a file or directory tree and ignores missing paths.
func RemoveFileIfExists ¶
RemoveFileIfExists removes a file and ignores missing paths.
func RunCmd ¶
func RunCmd(ctx context.Context, logger *slog.Logger, newCmd func(context.Context) *exec.Cmd, args ...string) error
RunCmd creates a command from newCmd, appends args, streams stdout at Debug and stderr at Info, and waits for it to finish.
func RunCmdAt ¶
func RunCmdAt(ctx context.Context, logger *slog.Logger, stderrLevel slog.Level, newCmd func(context.Context) *exec.Cmd, args ...string) error
RunCmdAt is like RunCmd but streams stderr at stderrLevel.
func ServiceExists ¶
ServiceExists checks whether a systemd unit file exists.
func StopService ¶
StopService stops a systemd service.