Hello,
Finally I found a workaround. Generate a list with all the configuration files
with a script in a ExecStartPre unit option, load the list into a enviroment
variable and pass them to the haproxy executable. I tried to avoid the use of a
external script, but due the particularities of systemd I couldn't make it to
work.
1.- Split the Haproxy configuration file.
1.1.- One file called "00-haproxy.conf" with the basic haproxy conf (in my
case global, defaults and listen stats). This must have the 00- at the begining
for listed it at first place in the script.
1.2.- One file for each listen section of for the different services
balanced, "some_name_a.conf". Each new balanced service will have a new file.
Note: I only define each balanced service in a listen section, not using
fronted and backed.
2.- Create a small script into "/usr/local/bin/haproxy-multiconf" with this
content:
#!/bin/bash
for file in /etc/haproxy/*.conf; do
test -f $file
CNF="$CNF -f $file"
done
echo "CONF='$CNF'" > /etc/haproxy/haproxy-multiconf.lst
3.- Change the systemd unit from this:
[Unit]
Description=HAProxy Load Balancer
After=network.target
[Service]
ExecStartPre=/usr/local/sbin/haproxy -f /etc/haproxy/haproxy.conf -c -q
ExecStart=/usr/local/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.conf
-p /run/haproxy.pid
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
[Install]
WantedBy=multi-user.target
To this:
[Unit]
Description=HAProxy Load Balancer
After=network.target
[Service]
ExecStartPre=/usr/local/bin/haproxy-multiconf
EnvironmentFile=/etc/haproxy/haproxy-multiconf.lst
ExecStartPre=/usr/local/sbin/haproxy -c -q $CONF
ExecStart=/usr/local/sbin/haproxy-systemd-wrapper -p /run/haproxy.pid $CONF
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
[Install]
WantedBy=multi-user.target
4.- Refresh systemd and run it:
systemctl daemon-reload
systemctl restart haproxy.service
I hope that this help to someone.
Regards,
________________________________
De: Ricardo Fraile <[email protected]>
Enviado: miƩrcoles, 23 de noviembre de 2016 12:43:20
Para: [email protected]
Asunto: Define path of configuration files in systemd unit
Hello,
I'm trying to use the "--" option for load multiple files in a systemd
unit, using the following file:
[Unit]
Description=HAProxy Load Balancer
After=network.target
[Service]
ExecStartPre=/usr/local/sbin/haproxy -c -q -- /etc/haproxy/*
ExecStart=/usr/local/sbin/haproxy-systemd-wrapper -p /run/haproxy.pid
-- /etc/haproxy/*
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
[Install]
WantedBy=multi-user.target
If I run "systemctl start haproxy.service" and "systemctl status
haproxy.service" the ExecStartPre report a Failue with "1".
But running the same command manually report "0"
/usr/local/sbin/haproxy -c -q -- /etc/haproxy/*
echo $?
0
Apart from this problem, the following is that the wrapper adds the
"-Ds" parameter at the end, and the previous "--" catch it as an other
argument, resulting in:
/usr/local/sbin/haproxy-systemd-wrapper -p /run/haproxy.pid
-- /etc/haproxy/*
<7>haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy
-p /run/haproxy.pid -- /etc/haproxy/haproxy.conf -Ds
[ALERT] 327/123043 (29118) : Could not open configuration file -Ds : No
such file or directory
<5>haproxy-systemd-wrapper: exit, haproxy RC=256
How is possible to define correctly a path with the configuration files
inside a systemd unit?
Thanks,