mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
fix: fail to control nginx
This commit is contained in:
parent
fcf789e271
commit
b6cbc34e6f
5 changed files with 27 additions and 13 deletions
|
@ -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),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":"2.0.0-beta.5","build_id":74,"total_build":278}
|
||||
{"version":"2.0.0-beta.5","build_id":75,"total_build":279}
|
|
@ -1 +1 @@
|
|||
{"version":"2.0.0-beta.5","build_id":74,"total_build":278}
|
||||
{"version":"2.0.0-beta.5","build_id":75,"total_build":279}
|
|
@ -6,6 +6,7 @@ import "strings"
|
|||
// nginx log level: debug, info, notice, warn, error, crit, alert, or emerg
|
||||
|
||||
const (
|
||||
Unknown = -1
|
||||
Debug = iota
|
||||
Info
|
||||
Notice
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue