Added start-/stopService methods

This commit is contained in:
Christian Muehlhaeuser 2018-03-27 10:07:41 +02:00
parent 7d4d46c459
commit 90e5792d0d
No known key found for this signature in database
GPG Key ID: BA4CF857DD4117E9
1 changed files with 46 additions and 0 deletions

View File

@ -92,3 +92,49 @@ func (ts Services) Strings() []string {
return res 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
}