Created
May 27, 2015 18:03
-
-
Save petomalina/3e975fc800336e1675e8 to your computer and use it in GitHub Desktop.
Example call of service from go-systemd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bus | |
/* | |
Libraries: go-systemd, godbus | |
Files: unit file in your systemd services location (.service) | |
*/ | |
import ( | |
"fmt" | |
"github.com/coreos/go-systemd/dbus" | |
) | |
// StartService starts given service by name | |
func StartService(name string) (string, error) { | |
bus, err := dbus.New() | |
if err != nil { | |
return "", err | |
} | |
defer bus.Close() | |
busChan := make(chan string) | |
id, err := bus.StartUnit("some-service.service", "fail", busChan) // rename your service | |
if err != nil { | |
return "", err | |
} | |
status := <-busChan | |
fmt.Println("Received return status id:", id, "status:", status) | |
return status, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment