mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-08 16:46:37 +08:00
fix(agent): recover OpenResty runtime after invalid PID (#45)
* fix(agent): recover OpenResty runtime after invalid PID * fix(agent): scope OpenResty shutdown to instance processes --------- Co-authored-by: Noru Wyrms <wyrmsnoru@gmail.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
// Copyright 2026 Arctel.net
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package nginx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//nolint:unused // Used by the non-Linux Unix inspector.
|
||||
const (
|
||||
psCommandIndex = 8
|
||||
psMasterBinaryIndex = 11
|
||||
)
|
||||
|
||||
//nolint:unused // Used by the non-Linux Unix inspector; portable for fixture tests.
|
||||
func parsePSRuntime(output, binary, configPath string, owner int) ([]runtimeProcess, error) {
|
||||
var processes []runtimeProcess
|
||||
for _, line := range strings.Split(output, "\n") {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) <= psCommandIndex {
|
||||
continue
|
||||
}
|
||||
uid, err := strconv.Atoi(fields[2])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
title := strings.Join(fields[psCommandIndex:], " ")
|
||||
if !strings.HasPrefix(title, "nginx: ") && !strings.HasPrefix(title, "openresty: ") {
|
||||
continue
|
||||
}
|
||||
master := uid == owner && matchesRuntimeMaster(title, configPath)
|
||||
if master && (len(fields) <= psMasterBinaryIndex || fields[psMasterBinaryIndex] != binary) {
|
||||
return nil, fmt.Errorf("cannot verify openresty master invocation %s", fields[0])
|
||||
}
|
||||
pid, err := strconv.Atoi(fields[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
parentPID, err := strconv.Atoi(fields[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
processes = append(processes, runtimeProcess{PID: pid, ParentPID: parentPID, Master: master, StartTime: strings.Join(fields[3:psCommandIndex], " ")})
|
||||
}
|
||||
return processes, nil
|
||||
}
|
||||
Reference in New Issue
Block a user