Skip to content

Commit

Permalink
watchdog installation path updates (#1787)
Browse files Browse the repository at this point in the history
  • Loading branch information
zackattack01 authored Jul 18, 2024
1 parent 7c5ce6a commit 385ac6e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ee/watchdog/controller_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
"fmt"
"log/slog"
"os"
"path/filepath"
"slices"
"time"

"github.com/kolide/launcher/ee/agent/flags/keys"
agentsqlite "github.com/kolide/launcher/ee/agent/storage/sqlite"
"github.com/kolide/launcher/ee/agent/types"
"github.com/kolide/launcher/pkg/backoff"
"github.com/kolide/launcher/pkg/launcher"
"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/mgr"
)
Expand Down Expand Up @@ -230,11 +232,23 @@ func (wc *WatchdogController) ServiceEnabledChanged(enabled bool) {
}
}

func (wc *WatchdogController) getExecutablePath() (string, error) {
defaultBinDir := launcher.DefaultPath(launcher.BinDirectory)
defaultLauncherLocation := filepath.Join(defaultBinDir, "launcher.exe")
// do some basic sanity checking to prevent installation from a bad path
_, err := os.Stat(defaultLauncherLocation)
if err != nil {
return "", err
}

return defaultLauncherLocation, nil
}

func (wc *WatchdogController) installService(serviceManager *mgr.Mgr) error {
ctx := context.TODO()
currentExe, err := os.Executable()
installedExePath, err := wc.getExecutablePath()
if err != nil {
return fmt.Errorf("collecting current executable path: %w", err)
return fmt.Errorf("determining watchdog executable path: %w", err)
}

svcMgrConf := mgr.Config{
Expand All @@ -255,7 +269,7 @@ func (wc *WatchdogController) installService(serviceManager *mgr.Mgr) error {

restartService, err := serviceManager.CreateService(
launcherWatchdogServiceName,
currentExe,
installedExePath,
svcMgrConf,
serviceArgs...,
)
Expand Down

0 comments on commit 385ac6e

Please sign in to comment.