X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cf2e2be269c5f8c575f18425dd32db2a16af8023..816f3bfd2b6a562fc712b7c2b3eb30157a95cb7e:/services/boot/systemd.go diff --git a/services/boot/systemd.go b/services/boot/systemd.go index e88ecc39df..18d123ea1a 100644 --- a/services/boot/systemd.go +++ b/services/boot/systemd.go @@ -1,34 +1,19 @@ package main import ( + "context" "fmt" - "os" "os/exec" ) -type supervisor interface { - Check() (bool, error) - Start() error -} - -func newSupervisor(name, cmd string, args ...string) supervisor { - return &systemdUnit{ - name: name, - cmd: cmd, - args: args, - } -} - type systemdUnit struct { name string - cmd string + cmd string args []string } -func (u *systemdUnit) Start() error { - cmd := exec.Command("systemd-run", append([]string{"--unit=arvados-"+u.name, u.cmd}, u.args...)...) - cmd.Stdout = os.Stderr - cmd.Stderr = os.Stderr +func (u *systemdUnit) Start(ctx context.Context) error { + cmd := command("systemd-run", append([]string{"--unit=arvados-" + u.name, u.cmd}, u.args...)...) err := cmd.Run() if err != nil { err = fmt.Errorf("systemd-run: %s", err) @@ -36,10 +21,12 @@ func (u *systemdUnit) Start() error { return err } -func (u *systemdUnit) Check() (bool, error) { - cmd := exec.Command("systemctl", "status", "arvados-"+u.name) - cmd.Stdout = os.Stderr - cmd.Stderr = os.Stderr +func (u *systemdUnit) Running(ctx context.Context) (bool, error) { + return runStatusCmd("systemctl", "status", "arvados-"+u.name) +} + +func runStatusCmd(prog string, args ...string) (bool, error) { + cmd := command(prog, args...) err := cmd.Run() switch err.(type) { case *exec.ExitError: