-
Notifications
You must be signed in to change notification settings - Fork 9
/
haproxyctl.go
46 lines (43 loc) · 906 Bytes
/
haproxyctl.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
package main
import (
"bytes"
"io/ioutil"
"net"
"os/exec"
)
// Execute haproxy command over administrative/stats socket
func HaproxyCtl(socket string, command []byte) error {
conn, err := net.Dial("unix", socket)
if err != nil {
return err
}
defer conn.Close()
_, err = conn.Write(command)
if err != nil {
return err
}
return nil
}
// Configuration reload
func HaproxyReload(binary, config, pidfile string) error {
pid, err := ioutil.ReadFile(pidfile)
args := make([]string, 1)
args = append(args, "-f")
args = append(args, config)
args = append(args, "-p")
args = append(args, pidfile)
if pid != nil {
args = append(args, "-sf")
args = append(args, string(pid))
}
cmd := exec.Command(binary, args...)
var out bytes.Buffer
cmd.Stdout = &out
err = cmd.Run()
if err != nil {
log.Err(err.Error())
return err
}
log.Info("HaproxyReload: " + out.String())
return nil
}