migrated to external IP allocator

This commit is contained in:
ston1th 2021-09-26 20:20:43 +02:00
commit e2449b425e
15 changed files with 478 additions and 194 deletions

View file

@ -10,9 +10,12 @@ import (
"os"
"os/exec"
"sync"
"syscall"
"text/template"
)
const Nobody = 65534
type ServiceManager interface {
Reload(context.Context) error
Status(context.Context) error
@ -21,6 +24,7 @@ type ServiceManager interface {
}
type HAProxyManager struct {
// protects config update
sync.Mutex
configFile string
@ -57,7 +61,24 @@ func (ha *HAProxyManager) checkConfig(ctx context.Context, lbs Config) (hash []b
return
}
hash = h.Sum(nil)
out, err := exec.CommandContext(ctx, "haproxy", "-c", "-f", tmp.Name()).CombinedOutput()
err = os.Chmod(tmp.Name(), 0640)
if err != nil {
return
}
err = os.Chown(tmp.Name(), -1, Nobody)
if err != nil {
return
}
cmd := exec.CommandContext(ctx, "haproxy", "-c", "-f", tmp.Name())
cmd.Dir = os.TempDir()
cmd.SysProcAttr = &syscall.SysProcAttr{
Credential: &syscall.Credential{
Uid: Nobody,
Gid: Nobody,
},
Setsid: true,
}
out, err := cmd.CombinedOutput()
if err != nil {
err = fmt.Errorf("%s:%w", string(out), err)
}