feat: inspect configurations #69

This commit is contained in:
0xJacky 2023-01-31 22:51:46 +08:00
parent 561771cf10
commit 768da42e35
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
23 changed files with 346 additions and 144 deletions

View file

@ -1,40 +1,30 @@
package nginx
import (
"errors"
"github.com/0xJacky/Nginx-UI/server/settings"
"log"
"os/exec"
"path/filepath"
"regexp"
"strings"
)
func TestConf() error {
func TestConf() string {
out, err := exec.Command("nginx", "-t").CombinedOutput()
if err != nil {
log.Println(err)
log.Println("[error] nginx.TestConf", err)
}
output := string(out)
if strings.Contains(output, "failed") {
return errors.New(output)
}
return nil
return string(out)
}
func Reload() string {
out, err := exec.Command("nginx", "-s", "reload").CombinedOutput()
if err != nil {
log.Println(err)
return err.Error()
log.Println("[error] nginx.Reload", err)
}
output := string(out)
if strings.Contains(output, "failed") {
return output
}
return ""
return string(out)
}
func GetConfPath(dir ...string) string {