Re: Define path of configuration files in systemd unit
Hello Patrick, You are right, with "exec" works: # systemctl status haproxy.service -l ● haproxy.service - HAProxy Load Balancer Loaded: loaded (/etc/systemd/system/haproxy.service; enabled) Active: active (running) since Mon 2016-12-19 12:23:28 CET; 1min 17s ago Process: 25403 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS) Process: 25230 ExecStartPre=/bin/sh -c exec /usr/local/sbin/haproxy -c -q -- /etc/haproxy/* (code=exited, status=0/SUCCESS) Main PID: 25231 (haproxy-systemd) CGroup: /system.slice/haproxy.service ├─25231 /usr/local/sbin/haproxy-systemd-wrapper -p /run/haproxy.pid -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf ├─25234 /usr/local/sbin/haproxy -Ds -p /run/haproxy.pid -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf └─25235 /usr/local/sbin/haproxy -Ds -p /run/haproxy.pid -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf Thanks, El mar, 13-12-2016 a las 11:56 -0500, Patrick Hemmer escribió: > On 2016/12/13 11:14, Ricardo Fraile wrote: > > Hello Jarno, > > > > > > Yes, you are right, this is not an elegant solution, and reloading > > doesn't work. This is the systemd report: > > > > > > # systemctl status haproxy.service -l > > ● haproxy.service - HAProxy Load Balancer > >Loaded: loaded (/etc/systemd/system/haproxy.service; enabled) > >Active: active (running) since Tue 2016-12-13 09:25:13 CET; 1s ago > > Process: 28736 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, > > status=0/SUCCESS) > > Process: 28764 ExecStartPre=/bin/sh -c /usr/local/sbin/haproxy -c -q > > -- /etc/haproxy/* (code=exited, status=0/SUCCESS) > > Main PID: 28766 (sh) > >CGroup: /system.slice/haproxy.service > >├─28766 /bin/sh -c /usr/local/sbin/haproxy-systemd-wrapper > > -p /run/haproxy.pid -- /etc/haproxy/* > >├─28769 /usr/local/sbin/haproxy-systemd-wrapper > > -p /run/haproxy.pid > > -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf > >├─28770 /usr/local/sbin/haproxy -Ds -p /run/haproxy.pid > > -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf > >└─28771 /usr/local/sbin/haproxy -Ds -p /run/haproxy.pid > > -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf > > > > > > Thanks, > > > > > > El lun, 12-12-2016 a las 19:36 +0200, Jarno Huuskonen escribió: > > > Hi Ricardo, > > > > > > On Mon, Dec 12, Ricardo Fraile wrote: > > > > Yes, shell expansion did the trick, this is the working systemd unit: > > > > > > > > > > > > [Unit] > > > > Description=HAProxy Load Balancer > > > > After=network.target > > > > > > > > [Service] > > > > ExecStartPre=/bin/sh -c "/usr/local/sbin/haproxy -c -q > > > > -- /etc/haproxy/*" > > > > ExecStart=/bin/sh -c "/usr/local/sbin/haproxy-systemd-wrapper > > > > -p /run/haproxy.pid -- /etc/haproxy/*" > > > > ExecReload=/bin/kill -USR2 $MAINPID > > > Does the /bin/sh -c add extra process to haproxy process tree ? > > > Does systemctl status haproxy that "Main PID:" belongs to > > > haproxy-systemd-wrapper process and reloading config works ? > > > > > > -Jarno > > > > > You can solve that specific issue easily by adding `exec` to the > command. > > ExecStart=/bin/sh -c "exec /usr/local/sbin/haproxy-systemd-wrapper > -p /run/haproxy.pid -- /etc/haproxy/*" > > -Patrick
Re: Define path of configuration files in systemd unit
On 2016/12/13 11:14, Ricardo Fraile wrote: > Hello Jarno, > > > Yes, you are right, this is not an elegant solution, and reloading > doesn't work. This is the systemd report: > > > # systemctl status haproxy.service -l > ● haproxy.service - HAProxy Load Balancer >Loaded: loaded (/etc/systemd/system/haproxy.service; enabled) >Active: active (running) since Tue 2016-12-13 09:25:13 CET; 1s ago > Process: 28736 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, > status=0/SUCCESS) > Process: 28764 ExecStartPre=/bin/sh -c /usr/local/sbin/haproxy -c -q > -- /etc/haproxy/* (code=exited, status=0/SUCCESS) > Main PID: 28766 (sh) >CGroup: /system.slice/haproxy.service >├─28766 /bin/sh -c /usr/local/sbin/haproxy-systemd-wrapper > -p /run/haproxy.pid -- /etc/haproxy/* >├─28769 /usr/local/sbin/haproxy-systemd-wrapper > -p /run/haproxy.pid > -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf >├─28770 /usr/local/sbin/haproxy -Ds -p /run/haproxy.pid > -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf >└─28771 /usr/local/sbin/haproxy -Ds -p /run/haproxy.pid > -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf > > > Thanks, > > > El lun, 12-12-2016 a las 19:36 +0200, Jarno Huuskonen escribió: >> Hi Ricardo, >> >> On Mon, Dec 12, Ricardo Fraile wrote: >>> Yes, shell expansion did the trick, this is the working systemd unit: >>> >>> >>> [Unit] >>> Description=HAProxy Load Balancer >>> After=network.target >>> >>> [Service] >>> ExecStartPre=/bin/sh -c "/usr/local/sbin/haproxy -c -q >>> -- /etc/haproxy/*" >>> ExecStart=/bin/sh -c "/usr/local/sbin/haproxy-systemd-wrapper >>> -p /run/haproxy.pid -- /etc/haproxy/*" >>> ExecReload=/bin/kill -USR2 $MAINPID >> Does the /bin/sh -c add extra process to haproxy process tree ? >> Does systemctl status haproxy that "Main PID:" belongs to >> haproxy-systemd-wrapper process and reloading config works ? >> >> -Jarno >> You can solve that specific issue easily by adding `exec` to the command. ExecStart=/bin/sh -c "exec /usr/local/sbin/haproxy-systemd-wrapper -p /run/haproxy.pid -- /etc/haproxy/*" -Patrick
Re: Define path of configuration files in systemd unit
Hello Jarno, Yes, you are right, this is not an elegant solution, and reloading doesn't work. This is the systemd report: # systemctl status haproxy.service -l ● haproxy.service - HAProxy Load Balancer Loaded: loaded (/etc/systemd/system/haproxy.service; enabled) Active: active (running) since Tue 2016-12-13 09:25:13 CET; 1s ago Process: 28736 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS) Process: 28764 ExecStartPre=/bin/sh -c /usr/local/sbin/haproxy -c -q -- /etc/haproxy/* (code=exited, status=0/SUCCESS) Main PID: 28766 (sh) CGroup: /system.slice/haproxy.service ├─28766 /bin/sh -c /usr/local/sbin/haproxy-systemd-wrapper -p /run/haproxy.pid -- /etc/haproxy/* ├─28769 /usr/local/sbin/haproxy-systemd-wrapper -p /run/haproxy.pid -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf ├─28770 /usr/local/sbin/haproxy -Ds -p /run/haproxy.pid -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf └─28771 /usr/local/sbin/haproxy -Ds -p /run/haproxy.pid -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf /etc/haproxy/zz.conf Thanks, El lun, 12-12-2016 a las 19:36 +0200, Jarno Huuskonen escribió: > Hi Ricardo, > > On Mon, Dec 12, Ricardo Fraile wrote: > > Yes, shell expansion did the trick, this is the working systemd unit: > > > > > > [Unit] > > Description=HAProxy Load Balancer > > After=network.target > > > > [Service] > > ExecStartPre=/bin/sh -c "/usr/local/sbin/haproxy -c -q > > -- /etc/haproxy/*" > > ExecStart=/bin/sh -c "/usr/local/sbin/haproxy-systemd-wrapper > > -p /run/haproxy.pid -- /etc/haproxy/*" > > ExecReload=/bin/kill -USR2 $MAINPID > > Does the /bin/sh -c add extra process to haproxy process tree ? > Does systemctl status haproxy that "Main PID:" belongs to > haproxy-systemd-wrapper process and reloading config works ? > > -Jarno >
Re: Define path of configuration files in systemd unit
Hi Ricardo, On Mon, Dec 12, Ricardo Fraile wrote: > Yes, shell expansion did the trick, this is the working systemd unit: > > > [Unit] > Description=HAProxy Load Balancer > After=network.target > > [Service] > ExecStartPre=/bin/sh -c "/usr/local/sbin/haproxy -c -q > -- /etc/haproxy/*" > ExecStart=/bin/sh -c "/usr/local/sbin/haproxy-systemd-wrapper > -p /run/haproxy.pid -- /etc/haproxy/*" > ExecReload=/bin/kill -USR2 $MAINPID Does the /bin/sh -c add extra process to haproxy process tree ? Does systemctl status haproxy that "Main PID:" belongs to haproxy-systemd-wrapper process and reloading config works ? -Jarno -- Jarno Huuskonen
Re: Define path of configuration files in systemd unit
Hi Jarno, Yes, shell expansion did the trick, this is the working systemd unit: [Unit] Description=HAProxy Load Balancer After=network.target [Service] ExecStartPre=/bin/sh -c "/usr/local/sbin/haproxy -c -q -- /etc/haproxy/*" ExecStart=/bin/sh -c "/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 I didn't know the new behavior of "-f" in v.1.7, that fit better with the bash pattern substitution in proposed by Willy ${CONF[@]/#/-f } Thanks, El lun, 12-12-2016 a las 16:28 +0200, Jarno Huuskonen escribió: > Hi, > > On Mon, Dec 12, Ricardo Fraile wrote: > > But the systemd execution is still a issue with the following unit: > > > > [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 > > [...] > > > > > Executing the same process that return the error from the terminal > > report > > /usr/local/sbin/haproxy -c -q -- /etc/haproxy/* > > echo $? > > 0 > > I think systemd doesn't do shell expansion on "/etc/haproxy/*". Does > it work from terminal if you run: > /usr/local/sbin/haproxy -c -q -- '/etc/haproxy/*' ; echo $? > (single quotes around '/etc/haproxy/*') ? > > Have you tried with haproxy 1.7 ? With 1.7: > " - support of directories for config files : now if the argument to -f > is a directory, all files found there are loaded in alphabetical > order. Additionally, files can be specified after "--" without having > to repeat "-f". > " > > Or you could try to use something like > /bin/sh -c "/usr/local/sbin/haproxy -c -q -- /etc/haproxy/*" as the > ExecStartPre/ExecStart command. (This might leave extra /bin/sh > process ...) > > -Jarno >
Re: Define path of configuration files in systemd unit
Hi, On Mon, Dec 12, Ricardo Fraile wrote: > But the systemd execution is still a issue with the following unit: > > [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 [...] > > Executing the same process that return the error from the terminal > report > /usr/local/sbin/haproxy -c -q -- /etc/haproxy/* > echo $? > 0 I think systemd doesn't do shell expansion on "/etc/haproxy/*". Does it work from terminal if you run: /usr/local/sbin/haproxy -c -q -- '/etc/haproxy/*' ; echo $? (single quotes around '/etc/haproxy/*') ? Have you tried with haproxy 1.7 ? With 1.7: " - support of directories for config files : now if the argument to -f is a directory, all files found there are loaded in alphabetical order. Additionally, files can be specified after "--" without having to repeat "-f". " Or you could try to use something like /bin/sh -c "/usr/local/sbin/haproxy -c -q -- /etc/haproxy/*" as the ExecStartPre/ExecStart command. (This might leave extra /bin/sh process ...) -Jarno -- Jarno Huuskonen
Re: Define path of configuration files in systemd unit
Hello Willy, I modified the haproxy-systemd-wrapper with the attached patch and it works ok from the terminal: # /usr/local/sbin/haproxy-systemd-wrapper -p /run/haproxy.pid -- /etc/haproxy/* <7>haproxy-systemd-wrapper: executing /usr/local/sbin/haproxy -Ds -p /run/haproxy.pid -- /etc/haproxy/haproxy.conf /etc/haproxy/z.conf But the systemd execution is still a issue with the following unit: [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 ● haproxy.service - HAProxy Load Balancer Loaded: loaded (/etc/systemd/system/haproxy.service; enabled) Active: failed (Result: start-limit) since Mon 2016-12-12 12:28:45 CET; 2s ago Process: 5896 ExecStartPre=/usr/local/sbin/haproxy -c -q -- /etc/haproxy/* (code=exited, status=1/FAILURE) Main PID: 5858 (code=exited, status=0/SUCCESS) Dec 12 12:28:45 balback1b.pre.es.sys.idealista systemd[1]: haproxy.service: control process exited, code=exited status=1 Dec 12 12:28:45 balback1b.pre.es.sys.idealista systemd[1]: Failed to start HAProxy Load Balancer. Dec 12 12:28:45 balback1b.pre.es.sys.idealista systemd[1]: Unit haproxy.service entered failed state. Dec 12 12:28:45 balback1b.pre.es.sys.idealista systemd[1]: haproxy.service start request repeated too quickly, refusing...art. Dec 12 12:28:45 balback1b.pre.es.sys.idealista systemd[1]: Failed to start HAProxy Load Balancer. Dec 12 12:28:45 balback1b.pre.es.sys.idealista systemd[1]: Unit haproxy.service entered failed state. Executing the same process that return the error from the terminal report /usr/local/sbin/haproxy -c -q -- /etc/haproxy/* echo $? 0 I continue looking for the problem, but now, I think that it's close to the systemd side. Thanks, El lun, 05-12-2016 a las 19:40 +0100, Willy Tarreau escribió: > Hi Ricardo, > > On Mon, Dec 05, 2016 at 11:55:44AM +, Ricardo Fraile wrote: > > 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. > > (...) > > I *think* that the problem you describe is in fact more related to the > systemd wrapper itself, am I wrong ? Maybe we need to modify it to > pass -Ds first > > > 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 > > Does systemd support bash-like pattern substitution ? In this case, you > could use something like ${CONF[@]/#/-f } to prepend "-f" in front of > each file. > > Regards, > Willy From f6d0203e8dbf0046203bd105513dd8b55719be63 Mon Sep 17 00:00:00 2001 From: rfraileDate: Mon, 12 Dec 2016 12:40:11 +0100 Subject: [PATCH] Fix systemd-wrapper issue with multiconf argument --- src/haproxy-systemd-wrapper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/haproxy-systemd-wrapper.c b/src/haproxy-systemd-wrapper.c index f6a9c85..2616e2f 100644 --- a/src/haproxy-systemd-wrapper.c +++ b/src/haproxy-systemd-wrapper.c @@ -114,9 +114,9 @@ static void spawn_haproxy(char **pid_strv, int nb_pid) locate_haproxy(haproxy_bin, 512); argv[argno++] = haproxy_bin; + argv[argno++] = "-Ds"; for (i = 0; i < main_argc; ++i) argv[argno++] = main_argv[i]; - argv[argno++] = "-Ds"; if (nb_pid > 0) { argv[argno++] = "-sf"; for (i = 0; i < nb_pid; ++i) -- 2.1.4
Re: Define path of configuration files in systemd unit
Hi Ricardo, On Mon, Dec 05, 2016 at 11:55:44AM +, Ricardo Fraile wrote: > 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. (...) I *think* that the problem you describe is in fact more related to the systemd wrapper itself, am I wrong ? Maybe we need to modify it to pass -Ds first > 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 Does systemd support bash-like pattern substitution ? In this case, you could use something like ${CONF[@]/#/-f } to prepend "-f" in front of each file. Regards, Willy
Re: Define path of configuration files in systemd unit
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 <rfra...@idealista.com> Enviado: miércoles, 23 de noviembre de 2016 12:43:20 Para: haproxy@formilux.org 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,
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,