mirror of
https://github.com/fleetdm/fleet
synced 2026-05-22 16:39:01 +00:00
Fleetctl preview to clean up osquery socket before starting orbit (#4729)
* Fleetctl preview to clean up osquery socket before starting orbit * Use os.Remove
This commit is contained in:
parent
dc8921fed1
commit
eeb73a42db
2 changed files with 24 additions and 0 deletions
1
changes/4711-fleetctl-preview-cleanup-osquery-socket
Normal file
1
changes/4711-fleetctl-preview-cleanup-osquery-socket
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Fleetctl preview to clean up osquery socket files before running fleet-osquery.
|
||||
|
|
@ -629,6 +629,9 @@ func downloadOrbitAndStart(destDir, enrollSecret, address, orbitChannel, osquery
|
|||
if err := os.RemoveAll(path.Join(destDir, "orbit.db")); err != nil {
|
||||
fmt.Println("Warning: clearing orbit db dir:", err)
|
||||
}
|
||||
if err := cleanUpSocketFiles(destDir); err != nil {
|
||||
fmt.Println("Warning: cleaning up socket files:", err)
|
||||
}
|
||||
|
||||
updateOpt := update.DefaultOptions
|
||||
|
||||
|
|
@ -673,6 +676,26 @@ func downloadOrbitAndStart(destDir, enrollSecret, address, orbitChannel, osquery
|
|||
return nil
|
||||
}
|
||||
|
||||
// cleanUpSocketFiles cleans up fleet-osqueryd's socket file
|
||||
// ("orbit-osquery.em") and osquery extension socket files
|
||||
// ("orbit-osquery.em.*").
|
||||
func cleanUpSocketFiles(path string) error {
|
||||
entries, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read dir: %w", err)
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if !strings.HasPrefix(entry.Name(), "orbit-osquery.em") {
|
||||
continue
|
||||
}
|
||||
entryPath := filepath.Join(path, entry.Name())
|
||||
if err := os.Remove(entryPath); err != nil {
|
||||
return fmt.Errorf("remove %q: %w", entryPath, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func stopOrbit(destDir string) error {
|
||||
err := killFromPIDFile(destDir, "osquery.pid", "osqueryd")
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue