20

Installed a new Ubuntu 10.04 server and logging in as root I installed haproxy using apt-get.

I can run haproxy directly as a daemon but when I do /etc/init.d/haproxy start nothing happens.. not even an error message.

netstat -a shows nothing is using the http port I'm trying to balance with haproxy...

Ideas?

Edit

  1. I noticed that apt-get install haproxy says this in the end:

    update-rc.d: warning: /etc/init.d/haproxy missing LSB information update-rc.d: see http://wiki.debian.org/LSBInitScripts

  2. /etc/default/haproxy says ENABLED=1

Debugging Output for sh -xv /etc/init.d/haproxy start

#!/bin/sh
#
# chkconfig: - 85 15
# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \
#              for high availability environments.
# processname: haproxy
# config: /etc/haproxy.cfg
# pidfile: /var/run/haproxy.pid

# Source function library.
if [ -f /etc/init.d/functions ]; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi
+ [ -f /etc/init.d/functions ]
+ [ -f /etc/rc.d/init.d/functions ]
+ exit 0
root@li267-63:~#
Assaf Lavie
  • 2,223

9 Answers9

39

Edit /etc/default/haproxy and make sure it has a line that says ENABLED=1 in it.

The default is ENABLED=0. This is done because haproxy has no sane default configuration, so you need to first configure it, then enable it.

SpamapS
  • 20,110
3

I know this a year old thread.. but just trying to share what i have learned..

use /etc/init.d/haproxy reload or service haproxy reload and it will reload fine.. afterall we just want it to start right ;)

devav2
  • 37,290
3

I had the same issue, where setting ENABLED had no effect due to the "test" line always failing. Found the reason: you have to edit /etc/default/haproxy instead of the init script.

Jorge Castro
  • 73,717
2

I ran into this same issue after first installing the ubuntu maintained package and then (after realizing the version did not support the feature i needed) Installing a ppa newer version of haproxy. The init.d script that i wound up with pointed to /usr/sbin/haproxy when in fact my executable was in /usr/local/sbin/haproxy. the debug output "sh -xv /etc/init.d/haproxy start" mentioned earlier made this problem pretty obvious.

2

I have a similar problem. I already set ENABLED=1, but the default update-rc.d config seems to be to put the haproxy in K20 (rc0|1|6.d) and in S20 (rc2|3|4|5.d). Which means it will try to start before networking, so in my case I get this in boot.log:-

 * Starting haproxy haproxy                                                     [ALERT] 346/160552 (927) : Starting proxy haproxy: cannot bind socket
[ALERT] 346/160552 (927) : Starting proxy haproxy: cannot bind socket
[ALERT] 346/160552 (927) : Starting proxy haproxy: cannot bind socket
[ALERT] 346/160552 (927) : Starting proxy haproxy: cannot bind socket
[ALERT] 346/160552 (927) : Starting proxy haproxy: cannot bind socket
[ALERT] 346/160552 (927) : Starting proxy haproxy: cannot bind socket
[ALERT] 346/160552 (927) : Starting proxy haproxy: cannot bind socket
                                                                         [fail]

changing the startup number to 35 seems to fix it, but I think 36 would be safer (the old number for networking was 35, so best make it start after that). So try:-

update-rc.d -f haproxy remove
update-rc.d haproxy start 35 2 3 4 5 . stop 20 0 1 6 .

Then reboot, and it should sort it. The package maintainers really should have thought of this.

2

Did you try to start it as root, or with sudo? If you are like me, you sometimes forget to add sudo to the front of the commands. I tried all your commands without sudo, and they failed as you described. However, with sudo in front of them, using a default haproxy.cfg file from install, it is now running without problems. Just thought I'd point that even with the correct configs, for me it won't go without sudo.

belacqua
  • 23,540
1

I just encountered the same issue with the haproxy init.d script on lucid. I simply couldn't get haproxy to start, so I looked it up and found you had to change the ENABLED variable in the /etc/init.d/haproxy script.

Changing this variable however did NOT help at all and this is why: A few lines lower in /etc/init.d/haproxy the ENABLED variable is checked by the script with the following line: test "$ENABLED" != "0" || exit 0. I noticed this test would ALWAYS fail on my system, no mather what the value of ENABLED. So the rest of the script is never run.

I must admit I do not really know why this test line doesn't work properly. But since we want haproxy to be enabled anyway, why bother checking?... Commenting out this test line made it work for me.

Hope this helps anyone.

0

I also kept staring at the scipt, couldn't see why it wasn't working despite the ENABLED=1 defined within the init-script.

Eventually, after looking down a bit, you'll see that the /etc/default/haproxy-file is sourced just before the test being performed, thus overwriting the set-variable in the init-script itself...

Seth
  • 59,332
ussr
  • 1
0

Ran into the same problem on azure with a debian vm. Turns out to be quite simple. The init script of haproxy uses run-time dependencies. On older system update-rc.d was the way to go, but on newer system insserv is used: https://wiki.debian.org/LSBInitScripts/DependencyBasedBoot

So if you have used update-rc.d to add the haproxy service on newer systems, you should do:

$ sudo update-rc.d -f haproxy remove

$ sudo insserv haproxy