haproxy-lb/pkg/haproxy/systemd.go
2021-04-09 22:38:03 +02:00

32 lines
764 B
Go

package haproxy
import (
"context"
"os/exec"
)
const systemctl = "systemctl"
type SystemdManager struct {
service string
}
func NewSystemdManager(service string) *SystemdManager {
return &SystemdManager{service}
}
func (sm *SystemdManager) Status(ctx context.Context) error {
return exec.CommandContext(ctx, systemctl, "status", sm.service).Run()
}
func (sm *SystemdManager) Start(ctx context.Context) error {
return exec.CommandContext(ctx, systemctl, "start", sm.service).Run()
}
func (sm *SystemdManager) Stop(ctx context.Context) error {
return exec.CommandContext(ctx, systemctl, "stop", sm.service).Run()
}
func (sm *SystemdManager) Reload(ctx context.Context) error {
return exec.CommandContext(ctx, systemctl, "reload", sm.service).Run()
}