Re: Help with environment variables in config
On Sat, Jul 21, 2018 at 05:44:44PM +0100, Jonathan Matthews wrote: > No. Sudo doesn't pass envvars through to its children by default: > https://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo > > Read that page *and* the comments - in particular be aware that you have to > request (at the CLI) that sudo preserve envvars, and you also have to have > been granted permission to do this, via the sudoers config file. > > If this is all sounding a bit complicated, that's because it is. > > You've chosen a relatively uncommon way of running haproxy - directly, via > sudo. Consider running via an init script or systemd unit (?) or, failing > that, just a script which is itself the sudo target, which sets the envvars > in the privileged environment. Also, something that people don't necessarily know is that haproxy can set its own variables using "setenv" in the global sections. Some will say this is stupid since you're going to use them in the same config, but when you add to this the fact that we can load multiple files, it becomes more obvious that it easily allows to parse an environment file first made of a global section with a few variables, then the regular (possibly shared) config. Typically it would do something like this : $ cat /etc/haproxy/env.cfg global setenv GRAPH_ADDRESS graph.server.com setenv GRAPH_PORT 8182 $ sudo haproxy -D -f /etc/haproxy/env.cfg -f /etc/haproxy/haproxy.cfg Hoping this helps, Willy
Re: Help with environment variables in config
No. Sudo doesn't pass envvars through to its children by default: https://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo Read that page *and* the comments - in particular be aware that you have to request (at the CLI) that sudo preserve envvars, and you also have to have been granted permission to do this, via the sudoers config file. If this is all sounding a bit complicated, that's because it is. You've chosen a relatively uncommon way of running haproxy - directly, via sudo. Consider running via an init script or systemd unit (?) or, failing that, just a script which is itself the sudo target, which sets the envvars in the privileged environment. J On Sat, 21 Jul 2018 at 17:31, jdtommy wrote: > would this chain of calls not work? > > ubuntu@ip-172-31-30-4:~$ export GRAPH_ADDRESS=graph.server.com > ubuntu@ip-172-31-30-4:~$ export GRAPH_PORT=8182 > ubuntu@ip-172-31-30-4:~$ sudo haproxy -d -V -f /etc/haproxy/haproxy.cfg > > On Sat, Jul 21, 2018 at 3:26 AM Igor Cicimov < > ig...@encompasscorporation.com> wrote: > >> On Sat, Jul 21, 2018 at 7:12 PM, Jonathan Matthews < >> cont...@jpluscplusm.com> wrote: >> >>> On Sat, 21 Jul 2018 at 09:12, jdtommy wrote: >>> I am setting them before I start haproxy in the terminal. I tried both starting it as a service and starting directly, but neither worked. It still would not forward it along. >>> >>> Make sure that, as well as setting them, you're *exporting* the envvars >>> before asking a child process (i.e. haproxy) to use them. >>> >>> J >>> -- >>> Jonathan Matthews >>> London, UK >>> http://www.jpluscplusm.com/contact.html >>> >> >> As Jonathan said, plus make sure they are included/exported in the init >> script or systemd file for the service. >> >> > > -- > Jarad Duersch > -- Jonathan Matthews London, UK http://www.jpluscplusm.com/contact.html
Re: Help with environment variables in config
actually, looking at this now I realize my sudo is messing it up. I need to set the env variables for the su environment. Yeah it works now. Thanks for helping me get to that conclusion. On Sat, Jul 21, 2018 at 10:31 AM jdtommy wrote: > would this chain of calls not work? > > ubuntu@ip-172-31-30-4:~$ export GRAPH_ADDRESS=graph.server.com > ubuntu@ip-172-31-30-4:~$ export GRAPH_PORT=8182 > ubuntu@ip-172-31-30-4:~$ sudo haproxy -d -V -f /etc/haproxy/haproxy.cfg > > On Sat, Jul 21, 2018 at 3:26 AM Igor Cicimov < > ig...@encompasscorporation.com> wrote: > >> On Sat, Jul 21, 2018 at 7:12 PM, Jonathan Matthews < >> cont...@jpluscplusm.com> wrote: >> >>> On Sat, 21 Jul 2018 at 09:12, jdtommy wrote: >>> I am setting them before I start haproxy in the terminal. I tried both starting it as a service and starting directly, but neither worked. It still would not forward it along. >>> >>> Make sure that, as well as setting them, you're *exporting* the envvars >>> before asking a child process (i.e. haproxy) to use them. >>> >>> J >>> -- >>> Jonathan Matthews >>> London, UK >>> http://www.jpluscplusm.com/contact.html >>> >> >> As Jonathan said, plus make sure they are included/exported in the init >> script or systemd file for the service. >> >> > > -- > Jarad Duersch > -- Jarad Duersch
Re: Help with environment variables in config
would this chain of calls not work? ubuntu@ip-172-31-30-4:~$ export GRAPH_ADDRESS=graph.server.com ubuntu@ip-172-31-30-4:~$ export GRAPH_PORT=8182 ubuntu@ip-172-31-30-4:~$ sudo haproxy -d -V -f /etc/haproxy/haproxy.cfg On Sat, Jul 21, 2018 at 3:26 AM Igor Cicimov wrote: > On Sat, Jul 21, 2018 at 7:12 PM, Jonathan Matthews < > cont...@jpluscplusm.com> wrote: > >> On Sat, 21 Jul 2018 at 09:12, jdtommy wrote: >> >>> I am setting them before I start haproxy in the terminal. I tried both >>> starting it as a service and starting directly, but neither worked. It >>> still would not forward it along. >>> >> >> Make sure that, as well as setting them, you're *exporting* the envvars >> before asking a child process (i.e. haproxy) to use them. >> >> J >> -- >> Jonathan Matthews >> London, UK >> http://www.jpluscplusm.com/contact.html >> > > As Jonathan said, plus make sure they are included/exported in the init > script or systemd file for the service. > > -- Jarad Duersch
Re: Help with environment variables in config
On Sat, Jul 21, 2018 at 7:12 PM, Jonathan Matthews wrote: > On Sat, 21 Jul 2018 at 09:12, jdtommy wrote: > >> I am setting them before I start haproxy in the terminal. I tried both >> starting it as a service and starting directly, but neither worked. It >> still would not forward it along. >> > > Make sure that, as well as setting them, you're *exporting* the envvars > before asking a child process (i.e. haproxy) to use them. > > J > -- > Jonathan Matthews > London, UK > http://www.jpluscplusm.com/contact.html > As Jonathan said, plus make sure they are included/exported in the init script or systemd file for the service.
Re: Help with environment variables in config
On Sat, 21 Jul 2018 at 09:12, jdtommy wrote: > I am setting them before I start haproxy in the terminal. I tried both > starting it as a service and starting directly, but neither worked. It > still would not forward it along. > Make sure that, as well as setting them, you're *exporting* the envvars before asking a child process (i.e. haproxy) to use them. J > -- Jonathan Matthews London, UK http://www.jpluscplusm.com/contact.html
Re: Help with environment variables in config
I am setting them before I start haproxy in the terminal. I tried both starting it as a service and starting directly, but neither worked. It still would not forward it along. On Sat, Jul 21, 2018, 2:06 AM Igor Cicimov wrote: > > > On Sat, Jul 21, 2018 at 4:49 PM, jdtommy wrote: > >> here is my simple `listen` section of the haproxy config file: >> >> listen graph_front >>bind *:8182 >>mode tcp >>server graph_server graph.server.com:8182 >> >> this works just fine, but I need the address and port to be a environment >> variable. So I changed it to this: >> >> listen graph_front >>bind *:8182 >>mode tcp >>server graph_server "$GRAPH_ADDRESS":"$GRAPH_PORT" >> >> the haproxy server restarts just fine, but it no longer forwards to the >> address in the environment variables. >> >> any ideas? >> > > Where are you setting the variables? > >
Re: Help with environment variables in config
On Sat, Jul 21, 2018 at 4:49 PM, jdtommy wrote: > here is my simple `listen` section of the haproxy config file: > > listen graph_front >bind *:8182 >mode tcp >server graph_server graph.server.com:8182 > > this works just fine, but I need the address and port to be a environment > variable. So I changed it to this: > > listen graph_front >bind *:8182 >mode tcp >server graph_server "$GRAPH_ADDRESS":"$GRAPH_PORT" > > the haproxy server restarts just fine, but it no longer forwards to the > address in the environment variables. > > any ideas? > Where are you setting the variables?
Help with environment variables in config
here is my simple `listen` section of the haproxy config file: listen graph_front bind *:8182 mode tcp server graph_server graph.server.com:8182 this works just fine, but I need the address and port to be a environment variable. So I changed it to this: listen graph_front bind *:8182 mode tcp server graph_server "$GRAPH_ADDRESS":"$GRAPH_PORT" the haproxy server restarts just fine, but it no longer forwards to the address in the environment variables. any ideas?