From b6cbc34e6f65ff1d6c45716f1499a43678d0128c Mon Sep 17 00:00:00 2001 From: 0xJacky Date: Wed, 6 Dec 2023 18:31:03 +0800 Subject: [PATCH] fix: fail to control nginx --- api/nginx/control.go | 14 +++++++------- app/src/version.json | 2 +- app/version.json | 2 +- internal/nginx/log.go | 3 ++- internal/nginx/nginx.go | 19 ++++++++++++++++--- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/api/nginx/control.go b/api/nginx/control.go index 50d22e0e..04fba566 100644 --- a/api/nginx/control.go +++ b/api/nginx/control.go @@ -1,31 +1,31 @@ package nginx import ( - nginx2 "github.com/0xJacky/Nginx-UI/internal/nginx" + "github.com/0xJacky/Nginx-UI/internal/nginx" "github.com/gin-gonic/gin" "net/http" ) func Reload(c *gin.Context) { - output := nginx2.Reload() + output := nginx.Reload() c.JSON(http.StatusOK, gin.H{ "message": output, - "level": nginx2.GetLogLevel(output), + "level": nginx.GetLogLevel(output), }) } func Test(c *gin.Context) { - output := nginx2.TestConf() + output := nginx.TestConf() c.JSON(http.StatusOK, gin.H{ "message": output, - "level": nginx2.GetLogLevel(output), + "level": nginx.GetLogLevel(output), }) } func Restart(c *gin.Context) { - output := nginx2.Restart() + output := nginx.Restart() c.JSON(http.StatusOK, gin.H{ "message": output, - "level": nginx2.GetLogLevel(output), + "level": nginx.GetLogLevel(output), }) } diff --git a/app/src/version.json b/app/src/version.json index d31ba32e..fdfd2068 100644 --- a/app/src/version.json +++ b/app/src/version.json @@ -1 +1 @@ -{"version":"2.0.0-beta.5","build_id":74,"total_build":278} \ No newline at end of file +{"version":"2.0.0-beta.5","build_id":75,"total_build":279} \ No newline at end of file diff --git a/app/version.json b/app/version.json index d31ba32e..fdfd2068 100644 --- a/app/version.json +++ b/app/version.json @@ -1 +1 @@ -{"version":"2.0.0-beta.5","build_id":74,"total_build":278} \ No newline at end of file +{"version":"2.0.0-beta.5","build_id":75,"total_build":279} \ No newline at end of file diff --git a/internal/nginx/log.go b/internal/nginx/log.go index bc22808e..b99acf7c 100644 --- a/internal/nginx/log.go +++ b/internal/nginx/log.go @@ -6,7 +6,8 @@ import "strings" // nginx log level: debug, info, notice, warn, error, crit, alert, or emerg const ( - Debug = iota + Unknown = -1 + Debug = iota Info Notice Warn diff --git a/internal/nginx/nginx.go b/internal/nginx/nginx.go index 8d3b8622..893eafd3 100644 --- a/internal/nginx/nginx.go +++ b/internal/nginx/nginx.go @@ -17,6 +17,15 @@ func execShell(cmd string) (out string) { return } +func execCommand(name string, cmd ...string) (out string) { + bytes, err := exec.Command(name, cmd...).CombinedOutput() + out = string(bytes) + if err != nil { + out += " " + err.Error() + } + return +} + func TestConf() (out string) { if settings.NginxSettings.TestConfigCmd != "" { out = execShell(settings.NginxSettings.TestConfigCmd) @@ -24,7 +33,7 @@ func TestConf() (out string) { return } - out = execShell("nginx -t") + out = execCommand("nginx", "-t") return } @@ -35,7 +44,7 @@ func Reload() (out string) { return } - out = execShell("nginx -s reload") + out = execCommand("nginx", "-s", "reload") return } @@ -47,7 +56,11 @@ func Restart() (out string) { return } - out = execShell("nginx -s reopen") + out = execCommand("nginx", "-s", "stop") + + out += execCommand("nginx") + + logger.Debug(out) return }