Skip to content

Commit fb1d82f

Browse files
committed
feat(logging): add debug logging for process checks in nginx
1 parent 1130047 commit fb1d82f

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

api/cluster/websocket.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/0xJacky/Nginx-UI/internal/analytic"
13+
"github.com/0xJacky/Nginx-UI/internal/kernel"
1314
"github.com/0xJacky/Nginx-UI/model"
1415
"github.com/gin-gonic/gin"
1516
"github.com/gorilla/websocket"
@@ -258,7 +259,8 @@ func (c *Client) writePump() {
258259
if err := c.conn.WriteMessage(websocket.PingMessage, nil); err != nil {
259260
return
260261
}
261-
262+
case <-kernel.Context.Done():
263+
return
262264
case <-c.ctx.Done():
263265
return
264266
}
@@ -292,5 +294,10 @@ func (c *Client) readPump() {
292294
}
293295
}()
294296

295-
<-c.ctx.Done()
297+
select {
298+
case <-kernel.Context.Done():
299+
return
300+
case <-c.ctx.Done():
301+
return
302+
}
296303
}

internal/nginx/nginx.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/0xJacky/Nginx-UI/internal/docker"
1212
"github.com/0xJacky/Nginx-UI/settings"
13+
"github.com/uozi-tech/cosy/logger"
1314
)
1415

1516
var (
@@ -119,26 +120,31 @@ func IsRunning() bool {
119120

120121
// isProcessRunning checks if the process with the PID from pidPath is actually running
121122
func isProcessRunning(pidPath string) bool {
123+
logger.Debugf("isProcessRunning pidPath: %s", pidPath)
122124
// Check if PID file exists
123125
if fileInfo, err := os.Stat(pidPath); err != nil || fileInfo.Size() == 0 {
126+
logger.Debugf("isProcessRunning pidPath: %s, err: %v", pidPath, err)
124127
return false
125128
}
126129

127130
// Read PID from file
128131
pidBytes, err := os.ReadFile(pidPath)
129132
if err != nil {
133+
logger.Debugf("isProcessRunning pidPath: %s, err: %v", pidPath, err)
130134
return false
131135
}
132136

133137
pidStr := strings.TrimSpace(string(pidBytes))
134138
pid, err := strconv.Atoi(pidStr)
135139
if err != nil {
140+
logger.Debugf("isProcessRunning pidPath: %s, err: %v", pidPath, err)
136141
return false
137142
}
138143

139144
// Cross-platform process existence check
140145
process, err := os.FindProcess(pid)
141146
if err != nil {
147+
logger.Debugf("isProcessRunning pidPath: %s, err: %v", pidPath, err)
142148
return false
143149
}
144150

@@ -148,7 +154,9 @@ func isProcessRunning(pidPath string) bool {
148154
err = process.Signal(syscall.Signal(0))
149155
if err == nil {
150156
// Process exists and we can signal it
157+
logger.Debugf("isProcessRunning pidPath: %s, process exists", pidPath)
151158
return true
152159
}
160+
logger.Debugf("isProcessRunning pidPath: %s, process does not exist", pidPath)
153161
return false
154162
}

internal/nginx/resolve_path.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ func GetPrefix() string {
4444
r, _ := regexp.Compile(`--prefix=(\S+)`)
4545
match := r.FindStringSubmatch(out)
4646
if len(match) < 1 {
47-
logger.Error("nginx.GetPrefix len(match) < 1")
48-
nginxPrefix = "/usr/local/nginx"
47+
logger.Debug("nginx.GetPrefix len(match) < 1")
48+
if runtime.GOOS == "windows" {
49+
nginxPrefix = GetNginxExeDir()
50+
} else {
51+
nginxPrefix = "/usr/local/nginx"
52+
}
4953
return nginxPrefix
5054
}
5155

0 commit comments

Comments
 (0)