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:~#
1
  • You can try to debug the start script with: sh -xv /etc/init.d/haproxy start Nov 30, 2010 at 20:46

9 Answers 9

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.

4
  • I set ENABLED=1, still nothing.. Nov 30, 2010 at 19:00
  • Assaf, you still need to configure haproxy. If the config file is not correct, it won't start, and probably has printed errors into the system logs (check /var/log/daemon.log and /var/log/syslog)
    – SpamapS
    Dec 4, 2010 at 8:50
  • 2
    Why it does not start without any verbose message? It's really confusing! May 10, 2012 at 11:59
  • 1
    @NikolayFominyh I agree, this is confusing! I eventually find this thread over and over because every 8 months or so I have to setup a new haproxy and I always forget about the requirement to enable services in /etc/default/*. I wish something would pop up in the syslog when you try to start a disabled service.
    – Jay Taylor
    Jul 10, 2013 at 17:52
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.

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

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
  • SiBaz, not sure what version of Ubuntu you're running, but in Lucid, the system the question was about, networking starts via upstart before rc-sysinit transitions to the default runlevel (2), which is what runs the /etc/rc2.d scripts.
    – SpamapS
    Dec 14, 2010 at 0:28
  • I'm using lucid too, and I can assure you networking hadn't started when haproxy was started via rc2.d/../init.d/haproxy. I've also noticed that, what I suggested didn't work, so I had to add networking to rc levels 2 3 4 5 to start before haproxy, update-rc.d networking start 35 2 3 4 5. I realise that's a hack, as the solution would be to add an upstart script. I've created a bug against the haproxy package on lucid to that effect.
    – SiBaz
    Dec 20, 2010 at 15:13
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.

1
  • I'd like to upvote this at least twice. Mar 2, 2015 at 12:53
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.

0
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.

1
  • I think you're supposed so set the enabled flag in /etc/default/haproxy
    – UpTheCreek
    Jan 13, 2013 at 20:06
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...

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .