// run calls systemctl with the given args, returning its standard output (and wrapped error) func run(args ...string) ([]byte, error) { bs, err := exec.Command("systemctl", args...).CombinedOutput() if err != nil { exitCode, _ := osutil.ExitCode(err) return nil, &Error{cmd: args, exitCode: exitCode, msg: bs} } return bs, nil }
// jctl calls journalctl to get the JSON logs of the given services, wrapping the error if any. func jctl(svcs []string) ([]byte, error) { cmd := []string{"journalctl", "-o", "json"} for i := range svcs { cmd = append(cmd, "-u", svcs[i]) } bs, err := exec.Command(cmd[0], cmd[1:]...).Output() // journalctl can be messy with its stderr if err != nil { exitCode, _ := osutil.ExitCode(err) return nil, &Error{cmd: cmd, exitCode: exitCode, msg: bs} } return bs, nil }