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)?

1 Answers1

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.

  • 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. – Michael - sqlbot Aug 29 '16 at 12:09