🛠️ fix:nginx reload命令报错

This commit is contained in:
iluobei
2026-04-04 22:13:41 +08:00
parent b3cafcadb2
commit bd3c03d51d
+11 -2
View File
@@ -2483,11 +2483,11 @@ func deployCertFiles(certPEM, keyPEM, certPath, keyPath, reloadTarget string) er
switch reloadTarget {
case "nginx":
return runCommand("nginx", "-s", "reload")
return reloadNginx()
case "xray":
return runCommand("systemctl", "restart", "xray")
case "both":
if err := runCommand("nginx", "-s", "reload"); err != nil {
if err := reloadNginx(); err != nil {
return err
}
return runCommand("systemctl", "restart", "xray")
@@ -2495,6 +2495,15 @@ func deployCertFiles(certPEM, keyPEM, certPath, keyPath, reloadTarget string) er
return nil
}
func reloadNginx() error {
for _, bin := range []string{"/usr/local/nginx/sbin/nginx", "nginx"} {
if path, err := exec.LookPath(bin); err == nil {
return runCommand(path, "-s", "reload")
}
}
return runCommand("systemctl", "reload", "nginx")
}
func runCommand(name string, args ...string) error {
if output, err := exec.Command(name, args...).CombinedOutput(); err != nil {
return fmt.Errorf("%s: %s: %w", name, string(output), err)