mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 15:05:20 +00:00
rkt: Refactor the systemd interface.
Replace shell out calls with dbus API calls. Remove unused 'Reload()'.
This commit is contained in:
@@ -18,7 +18,6 @@ package rkt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -60,10 +59,8 @@ type systemdInterface interface {
|
||||
StopUnit(name string, mode string, ch chan<- string) (int, error)
|
||||
// StopUnits restarts the unit with the given name.
|
||||
RestartUnit(name string, mode string, ch chan<- string) (int, error)
|
||||
// Reload is equivalent to 'systemctl daemon-reload'.
|
||||
Reload() error
|
||||
// ResetFailed is equivalent to 'systemctl reset-failed'.
|
||||
ResetFailed() error
|
||||
// ResetFailedUnit resets the "failed" state of a specific unit.
|
||||
ResetFailedUnit(name string) error
|
||||
}
|
||||
|
||||
// systemd implements the systemdInterface using dbus and systemctl.
|
||||
@@ -83,28 +80,13 @@ func newSystemd() (*systemd, error) {
|
||||
|
||||
// Version returns the version of the systemd.
|
||||
func (s *systemd) Version() (systemdVersion, error) {
|
||||
output, err := exec.Command("systemctl", "--version").Output()
|
||||
versionStr, err := s.Conn.GetManagerProperty("Version")
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
// Example output of 'systemctl --version':
|
||||
//
|
||||
// systemd 215
|
||||
// +PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR
|
||||
//
|
||||
lines := strings.Split(string(output), "\n")
|
||||
tuples := strings.Split(lines[0], " ")
|
||||
if len(tuples) != 2 {
|
||||
return -1, fmt.Errorf("rkt: Failed to parse version %v", lines)
|
||||
}
|
||||
result, err := strconv.Atoi(string(tuples[1]))
|
||||
result, err := strconv.Atoi(strings.Trim(versionStr, "\""))
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return systemdVersion(result), nil
|
||||
}
|
||||
|
||||
// ResetFailed calls 'systemctl reset failed'
|
||||
func (s *systemd) ResetFailed() error {
|
||||
return exec.Command("systemctl", "reset-failed").Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user