Implement kubeadm reset

This commit is contained in:
Lucas Käldström
2016-10-15 11:58:06 +03:00
parent e0fc43b42d
commit ecdaa7195a
4 changed files with 141 additions and 20 deletions

View File

@@ -17,11 +17,18 @@ limitations under the License.
package initsystem
import (
"fmt"
"os/exec"
"strings"
)
type InitSystem interface {
// ServiceStart tries to start a specific service
ServiceStart(service string) error
// ServiceStop tries to stop a specific service
ServiceStop(service string) error
// ServiceExists ensures the service is defined for this init system.
ServiceExists(service string) bool
@@ -34,6 +41,18 @@ type InitSystem interface {
type SystemdInitSystem struct{}
func (sysd SystemdInitSystem) ServiceStart(service string) error {
args := []string{"start", service}
_, err := exec.Command("systemctl", args...).Output()
return err
}
func (sysd SystemdInitSystem) ServiceStop(service string) error {
args := []string{"stop", service}
_, err := exec.Command("systemctl", args...).Output()
return err
}
func (sysd SystemdInitSystem) ServiceExists(service string) bool {
args := []string{"status", service}
outBytes, _ := exec.Command("systemctl", args...).Output()
@@ -70,11 +89,11 @@ func (sysd SystemdInitSystem) ServiceIsActive(service string) bool {
// getInitSystem returns an InitSystem for the current system, or nil
// if we cannot detect a supported init system for pre-flight checks.
// This indicates we will skip init system checks, not an error.
func GetInitSystem() InitSystem {
func GetInitSystem() (InitSystem, error) {
// Assume existence of systemctl in path implies this is a systemd system:
_, err := exec.LookPath("systemctl")
if err == nil {
return &SystemdInitSystem{}
return &SystemdInitSystem{}, nil
}
return nil
return nil, fmt.Errorf("no supported init system detected, skipping checking for services")
}