fix: fail to control nginx

This commit is contained in:
0xJacky 2023-12-06 18:31:03 +08:00
parent fcf789e271
commit b6cbc34e6f
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
5 changed files with 27 additions and 13 deletions

View file

@ -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

View file

@ -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
}