Skip to content

Commit

Permalink
add additional check to nginxProcesses (#483)
Browse files Browse the repository at this point in the history
* add additional check to nginx processes
Co-authored-by: Donal Hurley <[email protected]>
  • Loading branch information
aphralG authored Oct 3, 2023
1 parent ab97ac9 commit 70ffa9d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 5 deletions.
9 changes: 9 additions & 0 deletions scripts/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ echo "starting nginx ..."

nginx_pid=$!

SECONDS=0

while ! ps -ef | grep "nginx: master process" | grep -v grep; do
if (( SECONDS > 5 )); then
echo "couldn't find nginx master process"
exit 1
fi
done

cat /etc/nginx-agent/nginx-agent.conf;

# start nginx-agent, pass args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ echo "starting nginx ..."

nginx_pid=$!

SECONDS=0

while ! ps -ef | grep "nginx: master process" | grep -v grep; do
if (( SECONDS > 5 )); then
echo "couldn't find nginx master process"
exit 1
fi
done

cat /etc/nginx-agent/nginx-agent.conf;

# start nginx-agent, pass args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ echo "starting nginx ..."

nginx_pid=$!

SECONDS=0

while ! ps -ef | grep "nginx: master process" | grep -v grep; do
if (( SECONDS > 5 )); then
echo "couldn't find nginx master process"
exit 1
fi
done

cat /etc/nginx-agent/nginx-agent.conf;

# start nginx-agent, pass args
Expand Down
7 changes: 6 additions & 1 deletion src/core/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,10 @@ func (env *EnvironmentType) Processes() (result []*Process) {
name, _ := p.NameWithContext(ctx)
cmd, _ := p.CmdlineWithContext(ctx)

if name == "nginx" && !strings.Contains(cmd, "upgrade") {
if env.isNginxProcess(name, cmd) {
nginxProcesses[pid] = p
}

}

for pid, nginxProcess := range nginxProcesses {
Expand Down Expand Up @@ -654,6 +655,10 @@ func (env *EnvironmentType) Processes() (result []*Process) {
return processList
}

func (env *EnvironmentType) isNginxProcess(name string, cmd string) bool {
return name == "nginx" && !strings.Contains(cmd, "upgrade") && strings.HasPrefix(cmd, "nginx:")
}

func getNginxProcessExe(nginxProcess *process.Process) string {
exe, exeErr := nginxProcess.Exe()
if exeErr != nil {
Expand Down
37 changes: 37 additions & 0 deletions src/core/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,3 +1062,40 @@ func TestCGroupV1Check(t *testing.T) {
})
}
}

func TestGetNginxProcess(t *testing.T) {
tests := []struct {
name string
pName string
cmd string
expect bool
}{
{
name: "nginx process",
pName: "nginx",
cmd: "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf",
expect: true,
},
{
name: "non nginx process",
pName: "nginx-asg-sync",
cmd: "/usr/sbin/nginx-asg-sync -log_path=/var/log/nginx-asg-sync/nginx-asg-sync.log",
expect: false,
},
{
name: "upgrade process",
pName: "nginx-test",
cmd: "nginx: upgrade",
expect: false,
},
}

for _, tt := range tests {
env := EnvironmentType{}
isNginxProcess := false
t.Run(tt.name, func(t *testing.T) {
isNginxProcess = env.isNginxProcess(tt.pName, tt.cmd)
})
assert.Equal(t, tt.expect, isNginxProcess)
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 70ffa9d

Please sign in to comment.