2

I install Haproxy in /apps/haproxy/usr/local/sbin. Instead of placing config in /etc/haproxy/haproxy.cfg I want to use default config in /apps/haproxy/conf/haproxy.cfg and /etc/default/haproxy. How to start the Haproxy with the custom config location?

N.B I supposed to make haproxy application movable.

Introduction

I install Haproxy in machine with user which only have access in /apps. So i can not install anything which use /etc as config location. I found how to install haproxy in /apps, but the configs is not installed.

Update

Prom previous answer i understand the -f param to set haproxy.cfg location. How about config in /etc/default/haproxy? Is there way to run haproxy without referring /etc/default/haproxy (always ENABLED=1)?

3
  • Do you also have a file called /etc/init.d/haproxy? Take a look inside there. Commented Aug 26, 2016 at 12:21
  • Hi, @Michael-sqlbot actually i am not sure is the file in /etc/default/haproxy or /etc/init.d/haproxy. Please see my update in my question for details Commented Aug 29, 2016 at 11:34
  • From what are you installing haproxy? Are you compiling it yourself or installing from a binary? Commented Aug 29, 2016 at 11:53

1 Answer 1

2

Here's an example of a simple file I once created in an environment where I had limited flexibility and wasn't using any service control mechanisms. This script was executable and in the path, and was run to start or reload HAProxy. Customize with your paths. Line breaks added for clarity:

#!/usr/bin/bash

echo "validating configuration..."
/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -c \ 
&& echo "config is valid, reloading..." \
&& /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg \
-p /var/run/haproxy.pid \
-sf $(cat /var/run/haproxy.pid)

The -f specifies the config file, -c checks the config. If this fails, the && prevents the reload because the first run of HAProxy (validating the config) exits non-zero.

In the second invocation, -p specifies the pid file to which the new process should eventually write its process id, and -sf directs HAProxy to do a soft reload, taking over control from the process number returned from the old existing file. This will cause the old process to terminate itself once all of its existing connections are drained.

1
  • Great. If not, let us know what doesn't work. Note that #!/usr/bin/bash may also be wrong for your system. On Linux, I suspect you'll need #!/bin/bash instead. Commented Aug 29, 2016 at 12:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.