Skip to content

Commit 943f6fc

Browse files
committed
look for nginx-debug process
1 parent 852abe3 commit 943f6fc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pkg/nginxprocess/process.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ type Process struct {
3131
func (p *Process) IsWorker() bool { return strings.HasPrefix(p.Cmd, "nginx: worker") }
3232

3333
// IsMaster returns true if the process is a NGINX master process.
34-
func (p *Process) IsMaster() bool { return strings.HasPrefix(p.Cmd, "nginx: master") }
34+
func (p *Process) IsMaster() bool {
35+
return strings.HasPrefix(p.Cmd, "nginx: master") ||
36+
strings.HasPrefix(p.Cmd, "{nginx-debug} nginx: master")
37+
}
3538

3639
// IsShuttingDown returns true if the process is shutting down. This can identify workers that are in the process of a
3740
// graceful shutdown. See [changing NGINX configuration] for more details.
@@ -66,13 +69,14 @@ func convert(ctx context.Context, p *process.Process, o options) (*Process, erro
6669
}
6770

6871
name, _ := p.NameWithContext(ctx) // slow: shells out to ps
69-
if name != "nginx" {
72+
if name != "nginx" && name != "nginx-debug" {
7073
return nil, errNotAnNginxProcess
7174
}
7275

7376
cmdLine, _ := p.CmdlineWithContext(ctx) // slow: shells out to ps
7477
// ignore nginx processes in the middle of an upgrade
75-
if !strings.HasPrefix(cmdLine, "nginx:") || strings.Contains(cmdLine, "upgrade") {
78+
if !strings.HasPrefix(cmdLine, "nginx:") || !strings.HasPrefix(cmdLine, "{nginx-debug} nginx:") ||
79+
strings.Contains(cmdLine, "upgrade") {
7680
return nil, errNotAnNginxProcess
7781
}
7882

pkg/nginxprocess/process_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func TestProcess_IsNginxMaster(t *testing.T) {
8787
cmd: "nginx: cache manager process",
8888
want: false,
8989
},
90+
"Test 5: nginx debug master": {
91+
cmd: "{nginx-debug} nginx: master process /usr/sbin/nginx-debug -g daemon off;",
92+
want: true,
93+
},
94+
"Test 6: nginx debug worker": {
95+
cmd: "{nginx-debug} nginx: worker process;",
96+
want: false,
97+
},
9098
}
9199
for name, tc := range testcases {
92100
t.Run(name, func(t *testing.T) {

0 commit comments

Comments
 (0)