mirror of
https://github.com/DeBrosOfficial/orama.git
synced 2026-03-17 06:43:01 +00:00
Enhance PID collection by adding namespace service support and extending timeout for systemd queries
This commit is contained in:
parent
aa2da83969
commit
40600c3557
@ -2,6 +2,9 @@ package report
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -93,13 +96,49 @@ var managedServiceUnits = []string{
|
||||
// collectManagedPIDs queries systemd for the MainPID of each known service.
|
||||
// Returns a set of PIDs that are legitimately managed by systemd (not orphans).
|
||||
func collectManagedPIDs() map[int]bool {
|
||||
// Hard deadline: stop querying if this takes too long (e.g., node with many namespaces).
|
||||
deadline := time.Now().Add(10 * time.Second)
|
||||
pids := make(map[int]bool)
|
||||
|
||||
// Collect PIDs from global services.
|
||||
for _, unit := range managedServiceUnits {
|
||||
addMainPID(pids, unit)
|
||||
}
|
||||
|
||||
// Collect PIDs from namespace service instances.
|
||||
// Scan the namespaces data directory (same pattern as GetProductionServices).
|
||||
namespacesDir := "/opt/orama/.orama/data/namespaces"
|
||||
nsEntries, err := os.ReadDir(namespacesDir)
|
||||
if err == nil {
|
||||
nsServiceTypes := []string{"rqlite", "olric", "gateway"}
|
||||
for _, nsEntry := range nsEntries {
|
||||
if !nsEntry.IsDir() {
|
||||
continue
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
break
|
||||
}
|
||||
ns := nsEntry.Name()
|
||||
for _, svcType := range nsServiceTypes {
|
||||
envFile := filepath.Join(namespacesDir, ns, svcType+".env")
|
||||
if _, err := os.Stat(envFile); err == nil {
|
||||
unit := fmt.Sprintf("orama-namespace-%s@%s", svcType, ns)
|
||||
addMainPID(pids, unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pids
|
||||
}
|
||||
|
||||
// addMainPID queries systemd for a unit's MainPID and adds it to the set.
|
||||
func addMainPID(pids map[int]bool, unit string) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
out, err := runCmd(ctx, "systemctl", "show", unit, "--property=MainPID")
|
||||
cancel()
|
||||
if err != nil {
|
||||
continue
|
||||
return
|
||||
}
|
||||
props := parseProperties(out)
|
||||
if pidStr, ok := props["MainPID"]; ok {
|
||||
@ -108,8 +147,6 @@ func collectManagedPIDs() map[int]bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
return pids
|
||||
}
|
||||
|
||||
// isOramaProcess checks if a command string contains any orama-related process name.
|
||||
func isOramaProcess(command string) bool {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user