mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
fix: taking 100% CPU if the log file is not a regular file
This commit is contained in:
parent
f20d97a9fd
commit
d70e37c857
4 changed files with 21 additions and 8 deletions
|
@ -3,7 +3,6 @@ package nginx
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/0xJacky/Nginx-UI/api"
|
"github.com/0xJacky/Nginx-UI/api"
|
||||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
|
||||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -50,7 +49,7 @@ func GetNginxLogPage(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Open(logPath)
|
logFileStat, err := os.Stat(logPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, nginxLogPageResp{})
|
c.JSON(http.StatusOK, nginxLogPageResp{})
|
||||||
|
@ -58,7 +57,13 @@ func GetNginxLogPage(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logFileStat, err := os.Stat(logPath)
|
if !logFileStat.Mode().IsRegular() {
|
||||||
|
c.JSON(http.StatusOK, nginxLogPageResp{})
|
||||||
|
logger.Error("log file is not regular file:", logPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Open(logPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusOK, nginxLogPageResp{})
|
c.JSON(http.StatusOK, nginxLogPageResp{})
|
||||||
|
@ -188,8 +193,16 @@ func tailNginxLog(ws *websocket.Conn, controlChan chan controlStruct, errChan ch
|
||||||
Whence: io.SeekEnd,
|
Whence: io.SeekEnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !helper.FileExists(logPath) {
|
stat, err := os.Stat(logPath)
|
||||||
errChan <- errors.New("error log path not exists " + logPath)
|
if os.IsNotExist(err) {
|
||||||
|
errChan <- errors.New("[error] log path not exists " + logPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !stat.Mode().IsRegular() {
|
||||||
|
errChan <- errors.New("[error] " + logPath + " is not a regular file. " +
|
||||||
|
"If you are using nginx-ui in docker container, please refer to " +
|
||||||
|
"https://nginxui.com/zh_CN/guide/config-nginx-log.html for more information.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":"2.0.0-beta.11","build_id":109,"total_build":313}
|
{"version":"2.0.0-beta.11","build_id":110,"total_build":314}
|
|
@ -1 +1 @@
|
||||||
{"version":"2.0.0-beta.11","build_id":109,"total_build":313}
|
{"version":"2.0.0-beta.11","build_id":110,"total_build":314}
|
|
@ -8,7 +8,7 @@ StartCmd = bash
|
||||||
NodeSecret = fdc7764f-92d2-454c-9640-6a09be121139
|
NodeSecret = fdc7764f-92d2-454c-9640-6a09be121139
|
||||||
Demo = true
|
Demo = true
|
||||||
|
|
||||||
[nginx_log]
|
[nginx]
|
||||||
AccessLogPath = /var/log/nginx/access.local.log
|
AccessLogPath = /var/log/nginx/access.local.log
|
||||||
ErrorLogPath = /var/log/nginx/error.local.log
|
ErrorLogPath = /var/log/nginx/error.local.log
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue