Skip to content

Commit 8c3310e

Browse files
committed
BUG/MEDIUM: Fix relative path of haproxy files.
We want to use the haproxy config dir (where haproxy.cfg is located) as a base directory when loading files with relative path. This is mandatory the PatternFiles feature to work. For example if user provides "patterns/ips" as a patternfile and haproxy.cfg is in "/tmp/haproxy" then it will load the file from "/tmp/haproxy/patterns/ips". We used to do this by starting haproxy process from the config dir because by default relative path are loaded from the location the process is started in. But since introduction of s6 system the starting location of the haproxy process has changed breaking patternfiles. One possible fix was to force s6 to start haproxy from the config dir, however a more proper solution is to use the "default-path" keyword added in haproxy 2.4 to conigure this behavior. Which what was done in this fix. Also this resulted in the requirement of making the TransactionDir (for ClientNative) point to the config dir otherwise configuration checks would fail.
1 parent 09f3af8 commit 8c3310e

File tree

3 files changed

+2
-6
lines changed

3 files changed

+2
-6
lines changed

controller/configuration/main.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ type Env struct {
5757
MapDir string
5858
PatternDir string
5959
ErrFileDir string
60-
TransactionDir string
6160
}
6261

6362
// Init initialize configuration
@@ -176,9 +175,6 @@ func (c *ControllerCfg) envInit() (err error) {
176175
if c.Env.ErrFileDir == "" {
177176
c.Env.ErrFileDir = filepath.Join(c.Env.CfgDir, "errors")
178177
}
179-
if c.Env.TransactionDir == "" {
180-
c.Env.TransactionDir = filepath.Join(c.Env.CfgDir, "transactions")
181-
}
182178

183179
for _, d := range []string{
184180
c.Env.CertDir,
@@ -188,7 +184,6 @@ func (c *ControllerCfg) envInit() (err error) {
188184
c.Env.MapDir,
189185
c.Env.ErrFileDir,
190186
c.Env.StateDir,
191-
c.Env.TransactionDir,
192187
c.Env.PatternDir,
193188
} {
194189
err = os.MkdirAll(d, 0755)

controller/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (c *HAProxyController) Start() {
8080
logger.Panic(err)
8181
}
8282

83-
c.Client, err = api.Init(c.Cfg.Env.TransactionDir, c.Cfg.Env.MainCFGFile, c.Cfg.Env.HAProxyBinary, c.Cfg.Env.RuntimeSocket)
83+
c.Client, err = api.Init(c.Cfg.Env.CfgDir, c.Cfg.Env.MainCFGFile, c.Cfg.Env.HAProxyBinary, c.Cfg.Env.RuntimeSocket)
8484
if err != nil {
8585
logger.Panic(err)
8686
}

fs/usr/local/etc/haproxy/haproxy.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ global
1111
master-worker
1212
pidfile /var/run/haproxy.pid
1313
stats socket /var/run/haproxy-runtime-api.sock level admin expose-fd listeners
14+
default-path config
1415

1516
peers localinstance
1617
peer local 127.0.0.1:10000

0 commit comments

Comments
 (0)