diff --git a/runner/runner.go b/runner/runner.go index e647fb2..27e0cda 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -48,7 +48,7 @@ func (r *Runner) Run() error { SetContent(l). Save(context.Background()) if e != nil { - return fmt.Errorf("error creating log entry: %s", e) + return fmt.Errorf("error creating go build log entry: %s", e) } if m.MoveToTarget { if fl, e := copyFile( @@ -62,7 +62,7 @@ func (r *Runner) Run() error { SetContent(fl). Save(context.Background()) if e != nil { - return fmt.Errorf("error saving log entry: %s", e) + return fmt.Errorf("error creating move to target log entry: %s", e) } } } else { @@ -70,7 +70,17 @@ func (r *Runner) Run() error { return fmt.Errorf("error chowning binary: %s", e) } } - + if l, e := restartSystemdService(m.ServiceName); e != nil { + return fmt.Errorf("error restarting systemd service %s: %s", m.ServiceName, e) + } else { + _, e = r.client.Logentry. + Create(). + SetContent(l). + Save(context.Background()) + if e != nil { + return fmt.Errorf("error creating service restart log entry: %s", e) + } + } } } return nil @@ -146,3 +156,14 @@ func copyFile(src, dst string) (string, error) { return fmt.Sprintf("copied %d bytes from %s to %s", size, src, dst), nil } } + +// restartSystemdService restarts the named systemd service via systemctl restart shell command +func restartSystemdService(name string) (string, error) { + cmd := exec.Command("systemctl", "restart", name) + var out strings.Builder + cmd.Stdout = &out + if e := cmd.Run(); e != nil { + return "", e + } + return out.String(), nil +}