-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.go
58 lines (50 loc) · 1.09 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
package agent
import (
log "github.com/sirupsen/logrus"
"github.com/thetechnick/nginx-ingress/pkg/shell"
)
// Nginx controls a nginx process
type Nginx interface {
Run() error
Stop() error
Reload() error
TestConfig() error
}
type nginx struct {
log *log.Entry
executor shell.Executor
}
// NewNginx creates a new nginx instance
func NewNginx(e shell.Executor) Nginx {
if e == nil {
e = shell.NewShellExecutor()
}
return &nginx{
log: log.WithField("module", "nginx"),
executor: e,
}
}
func (n *nginx) Run() error {
n.log.Debug("starting nginx")
err := n.executor.Exec("nginx -g 'daemon off;'")
n.log.WithError(err).Debug("nginx stopped")
return err
}
func (n *nginx) Stop() error {
n.log.Debug("stopping nginx")
return n.executor.Exec("nginx -s quit")
}
func (n *nginx) Reload() error {
n.log.Debug("reloading nginx")
if err := n.TestConfig(); err != nil {
return err
}
if err := n.executor.Exec("nginx -s reload"); err != nil {
return err
}
return nil
}
func (n *nginx) TestConfig() error {
n.log.Debug("test nginx config")
return n.executor.Exec("nginx -t")
}