utilexec

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package utilexec provides simple command execution helpers for running commands on the host and inside nspawn machines with slog-based logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Azcmagent

func Azcmagent() func(context.Context) *exec.Cmd

Azcmagent returns a command factory for azcmagent.

func Bash

func Bash() func(context.Context) *exec.Cmd

Bash returns a command factory for bash.

func Curl

func Curl() func(context.Context) *exec.Cmd

Curl returns a command factory for curl.

func DisableService

func DisableService(ctx context.Context, logger *slog.Logger, serviceName string) error

DisableService disables a systemd service.

func Dpkg

func Dpkg() func(context.Context) *exec.Cmd

Dpkg returns a command factory for dpkg.

func IsServiceActive

func IsServiceActive(ctx context.Context, logger *slog.Logger, serviceName string) bool

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 Pgrep

func Pgrep() func(context.Context) *exec.Cmd

Pgrep returns a command factory for pgrep.

func ReloadSystemd

func ReloadSystemd(ctx context.Context, logger *slog.Logger) error

ReloadSystemd reloads systemd daemon configuration.

func RemoveAllIfExists

func RemoveAllIfExists(path string) error

RemoveAllIfExists removes a file or directory tree and ignores missing paths.

func RemoveFileIfExists

func RemoveFileIfExists(path string) error

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

func ServiceExists(ctx context.Context, logger *slog.Logger, serviceName string) bool

ServiceExists checks whether a systemd unit file exists.

func StopService

func StopService(ctx context.Context, logger *slog.Logger, serviceName string) error

StopService stops a systemd service.

func Systemctl

func Systemctl() func(context.Context) *exec.Cmd

Systemctl returns a command factory for systemctl.

func Wget

func Wget() func(context.Context) *exec.Cmd

Wget returns a command factory for wget.

Types

type Interface

type Interface interface {
	Command(name string, args ...string) *exec.Cmd
	CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd
}

Interface abstracts command creation for code that needs test injection.

func New

func New() Interface

New returns the default command executor.

Jump to

Keyboard shortcuts

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