-
Notifications
You must be signed in to change notification settings - Fork 487
/
Copy pathnginx.go
70 lines (52 loc) · 1.32 KB
/
nginx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package nginx
import (
"github.com/0xJacky/Nginx-UI/settings"
"os/exec"
)
func execShell(cmd string) (out string) {
bytes, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
out = string(bytes)
if err != nil {
out += " " + err.Error()
}
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)
return
}
out = execCommand("nginx", "-t")
return
}
func Reload() (out string) {
if settings.NginxSettings.ReloadCmd != "" {
out = execShell(settings.NginxSettings.ReloadCmd)
return
}
out = execCommand("nginx", "-s", "reload")
return
}
func Restart() (out string) {
if settings.NginxSettings.RestartCmd != "" {
out = execShell(settings.NginxSettings.RestartCmd)
return
}
pidPath := GetPIDPath()
daemon := GetSbinPath()
out = execCommand("start-stop-daemon", "--stop", "--quiet", "--oknodo", "--retry=TERM/30/KILL/5", "--pidfile", pidPath)
if daemon == "" {
out += execCommand("nginx")
return
}
out += execCommand("start-stop-daemon", "--start", "--quiet", "--pidfile", pidPath, "--exec", daemon)
return
}