mirror of
https://github.com/xiaoxinpro/nginx-proxy-manager-zh.git
synced 2025-01-23 13:18:14 -05:00
5e5f0de0e2
- Renamed host templates to nginx templates - Generate upstream templates - Better nginx error reporting when reloading - Use tparse for golang test reporting
43 lines
803 B
Go
43 lines
803 B
Go
package nginx
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"npm/internal/logger"
|
|
)
|
|
|
|
func reloadNginx() (string, error) {
|
|
return shExec([]string{"-s", "reload"})
|
|
}
|
|
|
|
func getNginxFilePath() (string, error) {
|
|
path, err := exec.LookPath("nginx")
|
|
if err != nil {
|
|
return path, fmt.Errorf("Cannot find nginx execuatable script in PATH")
|
|
}
|
|
return path, nil
|
|
}
|
|
|
|
// shExec executes nginx with arguments
|
|
func shExec(args []string) (string, error) {
|
|
ng, err := getNginxFilePath()
|
|
if err != nil {
|
|
logger.Error("NginxError", err)
|
|
return "", err
|
|
}
|
|
|
|
logger.Debug("CMD: %s %v", ng, args)
|
|
// nolint: gosec
|
|
c := exec.Command(ng, args...)
|
|
|
|
b, e := c.CombinedOutput()
|
|
|
|
if e != nil {
|
|
logger.Error("NginxError", fmt.Errorf("Command error: %s -- %v\n%+v", ng, args, e))
|
|
logger.Warn(string(b))
|
|
}
|
|
|
|
return string(b), e
|
|
}
|