-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.go
46 lines (38 loc) · 1.03 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
// mystack-router api
// https://github.com/topfreegames/mystack-router
//
// Licensed under the MIT license:
// http://www.opensource.org/licenses/mit-license
// Copyright © 2017 Top Free Games <backend@tfgco.com>
package nginx
import (
"github.com/Sirupsen/logrus"
"os"
"os/exec"
)
type Nginx struct{}
//Reload reloads nginx
func (*Nginx) Reload(logger logrus.FieldLogger) error {
logger.Info("reloading nginx")
cmd := exec.Command("nginx", "-s", "reload")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
logger.Fatal("Nginx exec error:", err)
return err
}
logger.Info("nginx successfully started")
return nil
}
//AssertConfig tests config file for correct syntax
func (*Nginx) AssertConfig(filePath string, logger logrus.FieldLogger) error {
cmd := exec.Command("nginx", "-t", "-c", filePath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
logger.Fatal("Nginx exec error:", err)
return err
}
logger.Info("correct nginx config file")
return nil
}