mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-09 00:56: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,44 @@
|
||||
// Copyright 2026 Arctel.net
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package nginx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func inspectOpenrestyProcesses(ctx context.Context, binary, configPath string) ([]runtimeProcess, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
path, err := exec.LookPath(binary)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
executable, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return inspectProcRuntime("/proc", executable, binary, configPath, os.Geteuid())
|
||||
}
|
||||
|
||||
func signalOpenrestyProcess(ctx context.Context, binary, config string, process runtimeProcess, quit bool) error {
|
||||
processes, err := inspectOpenrestyProcesses(ctx, binary, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, current := range processes {
|
||||
if current.PID == process.PID && current.Master && current.StartTime == process.StartTime {
|
||||
signal := syscall.SIGHUP
|
||||
if quit {
|
||||
signal = syscall.SIGQUIT
|
||||
}
|
||||
return syscall.Kill(current.PID, signal)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("openresty master identity changed before signalling pid %d", process.PID)
|
||||
}
|
||||
Reference in New Issue
Block a user