From 90e5792d0d91a9b4f0644b5d710b78681ead3c6c Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 27 Mar 2018 10:07:41 +0200 Subject: [PATCH] Added start-/stopService methods --- service-monitor/services.go | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/service-monitor/services.go b/service-monitor/services.go index 46b33c0..ded4f4e 100644 --- a/service-monitor/services.go +++ b/service-monitor/services.go @@ -92,3 +92,49 @@ func (ts Services) Strings() []string { return res } + +func startService(name string) error { + var err error + if conn == nil { + conn, err = dbus.New() + if err != nil { + return err + } + } + + reschan := make(chan string) + _, err = conn.StartUnit(name, "fail", reschan) + if err != nil { + return err + } + + job := <-reschan + if job != "done" { + return fmt.Errorf("failed starting service: %s", job) + } + + return nil +} + +func stopService(name string) error { + var err error + if conn == nil { + conn, err = dbus.New() + if err != nil { + return err + } + } + + reschan := make(chan string) + _, err = conn.StopUnit(name, "fail", reschan) + if err != nil { + return err + } + + job := <-reschan + if job != "done" { + return fmt.Errorf("failed stopping service: %s", job) + } + + return nil +}