Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
Bryan Frimin
2026-05-26 10:31:37 -07:00
parent e040851a4c
commit 7a3d3db7ac
13 changed files with 125 additions and 0 deletions

View File

@@ -74,6 +74,7 @@ func Install(cfg Config) error {
}
defer func() { _ = sf.Close() }()
if err := rcTmpl.Execute(sf, cfg); err != nil {
return fmt.Errorf("cannot render rc.d script: %w", err)
}

View File

@@ -70,6 +70,7 @@ func Install(cfg Config) error {
}
defer func() { _ = f.Close() }()
if err := tmpl.Execute(f, cfg); err != nil {
return fmt.Errorf("cannot render systemd unit: %w", err)
}
@@ -87,6 +88,7 @@ func Install(cfg Config) error {
func Uninstall(cfg Config) error {
_ = exec.Command("systemctl", "disable", "--now", "probo-agent.service").Run()
if err := os.Remove(systemdUnitPath); err != nil && !errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("cannot remove systemd unit: %w", err)
}

View File

@@ -26,9 +26,11 @@ func Install(cfg Config) error {
if cfg.ExePath == "" {
return errors.New("executable path is required")
}
if cfg.Dir == "" {
return errors.New("state directory is required")
}
name := DefaultWindowsName
bin := fmt.Sprintf(`"%s" run --dir "%s"`, cfg.ExePath, cfg.Dir)
@@ -45,6 +47,7 @@ func Install(cfg Config) error {
).CombinedOutput(); err != nil {
return fmt.Errorf("cannot run sc.exe create: %w: %s", err, strings.TrimSpace(string(out)))
}
// Restart on failure.
if out, err := exec.Command(
"sc.exe",
@@ -57,14 +60,17 @@ func Install(cfg Config) error {
).CombinedOutput(); err != nil {
return fmt.Errorf("cannot run sc.exe failure: %w: %s", err, strings.TrimSpace(string(out)))
}
if out, err := exec.Command("sc.exe", "start", name).CombinedOutput(); err != nil {
return fmt.Errorf("cannot run sc.exe start: %w: %s", err, strings.TrimSpace(string(out)))
}
return nil
}
func Uninstall(cfg Config) error {
name := DefaultWindowsName
_ = exec.Command("sc.exe", "stop", name).Run()
if out, err := exec.Command("sc.exe", "delete", name).CombinedOutput(); err != nil {
msg := strings.TrimSpace(string(out))
@@ -74,5 +80,6 @@ func Uninstall(cfg Config) error {
return fmt.Errorf("cannot run sc.exe delete: %w: %s", err, msg)
}
return nil
}

View File

@@ -18,6 +18,7 @@ import "strings"
func isWindowsServiceMissing(out string) bool {
lower := strings.ToLower(out)
return strings.Contains(lower, "1060") ||
strings.Contains(lower, "does not exist as an installed service") ||
strings.Contains(lower, "specified service does not exist")