When attempting to enable HAProxy statistics in version 1.7 on Ubuntu 16.04 LTS, the service fails to start with the following critical errors:
Job for haproxy.service failed because the control process exited with error code
Service started too quickly error
ExecStartPre=/usr/sbin/haproxy -f ${CONFIG} -c -q (code=exited, status=1/FAILURE)
The issue specifically occurs when adding the listen stats
block. Here's the problematic section from haproxy.cfg:
listen stats :9000
mode http
stats enable
stats hide-version
stats realm HAproxy-Statistics
stats uri /haproxy_stats
stats auth admin:password
There are two primary issues in the configuration:
- The
listen stats :9000
syntax is incorrect for HAProxy 1.7 - Missing proper frontend/backend declarations for statistics
Here's the corrected configuration that works with HAProxy 1.7:
frontend stats
bind *:9000
stats enable
stats hide-version
stats uri /haproxy_stats
stats realm HAproxy\ Statistics
stats auth admin:password
stats refresh 30s
stats admin if TRUE
backend no-op
option httpchk OPTIONS * HTTP/1.1\r\nHost:\ example.com
Key differences from the original configuration:
1. Uses proper frontend declaration instead of deprecated listen
2. Explicit bind statement with port 9000
3. Added stats refresh interval
4. Included backend section to avoid empty config warnings
5. Proper escaping for the stats realm space character
After making these changes:
sudo haproxy -f /etc/haproxy/haproxy.cfg -c
sudo systemctl restart haproxy
Verify the statistics page is accessible at:
http://your-server-ip:9000/haproxy_stats
For production environments, consider these enhancements:
frontend stats
bind 127.0.0.1:9000 # Restrict to localhost
acl internal_network src 192.168.1.0/24
http-request deny unless internal_network
stats admin if LOCALHOST # Only allow admin from localhost
If issues persist, check:
1. File permissions on /run/haproxy/admin.sock
2. SELinux/AppArmor restrictions
3. Port 9000 availability (netstat -tulnp)
4. HAProxy logs (/var/log/haproxy.log)
5. Systemd journal: journalctl -u haproxy -f
When configuring HAProxy 1.7 statistics on Ubuntu 16.04, many developers encounter the frustrating "Service started too quickly" error. The core issue stems from either configuration syntax errors or systemd service conflicts, not necessarily from the statistics module itself.
Let's examine a working configuration that resolves the startup issue while maintaining statistics functionality:
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
frontend http-in
bind *:80
default_backend servers
backend servers
balance roundrobin
server server1 127.0.0.1:8080 check
server server2 127.0.0.1:8081 check
listen stats
bind *:9000
mode http
stats enable
stats hide-version
stats uri /stats
stats realm Haproxy\ Statistics
stats auth admin:securepassword
- The
listen stats
section must include thebind *:9000
directive explicitly - Authentication credentials should use proper escaping for special characters
- Verify socket permissions match the configured user/group
Create or modify /etc/systemd/system/haproxy.service.d/override.conf
:
[Service]
RestartSec=5s
TimeoutStartSec=300
Then reload systemd:
sudo systemctl daemon-reload
sudo systemctl restart haproxy
After making these changes, verify the statistics page is accessible:
curl -u admin:securepassword http://localhost:9000/stats
Check the process status:
sudo systemctl status haproxy
And examine the socket:
sudo netstat -tulnp | grep haproxy