gofumpt against systemctl + add reenable

This commit is contained in:
Tai Groot
2022-10-23 23:26:52 -07:00
parent e44344ee7d
commit 33828cf7b9
3 changed files with 59 additions and 28 deletions

View File

@@ -15,7 +15,21 @@ import (
// reloaded, all sockets systemd listens on behalf of user configuration will
// stay accessible.
func DaemonReload(ctx context.Context, opts Options) error {
var args = []string{"daemon-reload", "--system"}
args := []string{"daemon-reload", "--system"}
if opts.UserMode {
args[1] = "--user"
}
_, _, _, err := execute(ctx, args)
return err
}
// 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 Reenable(ctx context.Context, unit string, opts Options) error {
args := []string{"reenable", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -29,7 +43,7 @@ func DaemonReload(ctx context.Context, opts Options) error {
// the unit configuration directory, and hence undoes any changes made by
// enable or link.
func Disable(ctx context.Context, unit string, opts Options) error {
var args = []string{"disable", "--system", unit}
args := []string{"disable", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -44,7 +58,7 @@ func Disable(ctx context.Context, unit string, opts Options) error {
// manager configuration is reloaded (in a way equivalent to daemon-reload),
// in order to ensure the changes are taken into account immediately.
func Enable(ctx context.Context, unit string, opts Options) error {
var args = []string{"enable", "--system", unit}
args := []string{"enable", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -57,7 +71,7 @@ func Enable(ctx context.Context, unit string, opts Options) error {
// Returns true if the unit is active, false if inactive or failed.
// Also returns false in an error case.
func IsActive(ctx context.Context, unit string, opts Options) (bool, error) {
var args = []string{"is-active", "--system", unit}
args := []string{"is-active", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -87,7 +101,7 @@ func IsActive(ctx context.Context, unit string, opts Options) (bool, error) {
// See https://www.freedesktop.org/software/systemd/man/systemctl.html#is-enabled%20UNIT%E2%80%A6
// for more information
func IsEnabled(ctx context.Context, unit string, opts Options) (bool, error) {
var args = []string{"is-enabled", "--system", unit}
args := []string{"is-enabled", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -127,7 +141,7 @@ func IsEnabled(ctx context.Context, unit string, opts Options) (bool, error) {
// Check whether any of the specified units are in a "failed" state.
func IsFailed(ctx context.Context, unit string, opts Options) (bool, error) {
var args = []string{"is-failed", "--system", unit}
args := []string{"is-failed", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -149,7 +163,7 @@ func IsFailed(ctx context.Context, unit string, opts Options) (bool, error) {
// continue masking anyway. Calling Mask on a non-existing masked unit does not
// return an error. Similarly, see Unmask.
func Mask(ctx context.Context, unit string, opts Options) error {
var args = []string{"mask", "--system", unit}
args := []string{"mask", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -160,7 +174,7 @@ func Mask(ctx context.Context, unit string, opts Options) error {
// 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 Restart(ctx context.Context, unit string, opts Options) error {
var args = []string{"restart", "--system", unit}
args := []string{"restart", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -171,7 +185,7 @@ func Restart(ctx context.Context, unit string, opts Options) error {
// 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 Show(ctx context.Context, unit string, property properties.Property, opts Options) (string, error) {
var args = []string{"show", "--system", unit, "--property", string(property)}
args := []string{"show", "--system", unit, "--property", string(property)}
if opts.UserMode {
args[1] = "--user"
}
@@ -183,7 +197,7 @@ func Show(ctx context.Context, unit string, property properties.Property, opts O
// Start (activate) a given unit
func Start(ctx context.Context, unit string, opts Options) error {
var args = []string{"start", "--system", unit}
args := []string{"start", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -197,7 +211,7 @@ func Start(ctx context.Context, unit string, opts Options) error {
// Generally, it makes more sense to programatically retrieve the properties
// using Show, but this command is provided for the sake of completeness
func Status(ctx context.Context, unit string, opts Options) (string, error) {
var args = []string{"status", "--system", unit}
args := []string{"status", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -207,7 +221,7 @@ func Status(ctx context.Context, unit string, opts Options) (string, error) {
// Stop (deactivate) a given unit
func Stop(ctx context.Context, unit string, opts Options) error {
var args = []string{"stop", "--system", unit}
args := []string{"stop", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}
@@ -223,7 +237,7 @@ func Stop(ctx context.Context, unit string, opts Options) error {
// If the unit doesn't exist but it's masked anyway, no error will be
// returned. Gross, I know. Take it up with Poettering.
func Unmask(ctx context.Context, unit string, opts Options) error {
var args = []string{"unmask", "--system", unit}
args := []string{"unmask", "--system", unit}
if opts.UserMode {
args[1] = "--user"
}