Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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:~#
share|improve this question
    
You can try to debug the start script with: sh -xv /etc/init.d/haproxy start –  João Pinto Nov 30 '10 at 20:46
add comment

8 Answers

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.

share|improve this answer
    
I set ENABLED=1, still nothing.. –  Assaf Lavie Nov 30 '10 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 '10 at 8:50
1  
Why it does not start without any verbose message? It's really confusing! –  Nikolay Fominyh May 10 '12 at 11:59
    
@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 '13 at 17:52
add comment

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.

share|improve this answer
    
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 '10 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 '10 at 15:13
add comment

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.

share|improve this answer
    
I think you're supposed so set the enabled flag in /etc/default/haproxy –  UpTheCreek Jan 13 '13 at 20:06
add comment

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.

share|improve this answer
    
:) yes, done as root –  Assaf Lavie Aug 17 '11 at 18:03
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.