nginx-proxy-manager-zh/backend/internal/nginx/exec.go

43 lines
834 B
Go
Raw Normal View History

2022-07-15 00:26:12 -04:00
package nginx
import (
"os/exec"
"npm/internal/logger"
2023-02-24 02:19:07 -05:00
"github.com/rotisserie/eris"
2022-07-15 00:26:12 -04:00
)
func reloadNginx() (string, error) {
return shExec([]string{"-s", "reload"})
2022-07-15 00:26:12 -04:00
}
func getNginxFilePath() (string, error) {
path, err := exec.LookPath("nginx")
if err != nil {
2023-02-24 02:19:07 -05:00
return path, eris.Wrapf(err, "Cannot find nginx execuatable script in PATH")
2022-07-15 00:26:12 -04:00
}
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()
2022-07-15 00:26:12 -04:00
if e != nil {
2023-05-30 21:35:24 -04:00
logger.Error("NginxError", eris.Wrapf(e, "Command error: %s -- %v\n%+v", ng, args, e))
2022-07-15 00:26:12 -04:00
logger.Warn(string(b))
}
return string(b), e
}