HAProxy Commands

HAProxy CLI commands and runtime API for load balancer management.

Service Startup Procedure

Step 1: Check configuration

Validate config before starting

haproxy -c -f /etc/haproxy/haproxy.cfg

Check configuration syntax

Step 2: Start service

Start HAProxy service

systemctl start haproxy

Start HAProxy via systemd

Step 3: Verify service

Check service is running

systemctl status haproxy

Check HAProxy status

echo "show info" | socat stdio /var/run/haproxy.sock

Display HAProxy information

Step 4: Check backends

Verify backend servers are up

echo "show servers state" | socat stdio /var/run/haproxy.sock

Display server states

Service Shutdown Procedure

Step 1: Check active connections

Review current sessions

echo "show sess" | socat stdio /var/run/haproxy.sock

Display current sessions

Step 2: Drain connections

Optionally drain before shutdown

echo "set server <backend>/<server> state drain" | socat stdio /var/run/haproxy.sock

Drain server connections

Step 3: Stop service

Stop HAProxy service

systemctl stop haproxy

Stop HAProxy service

Step 4: Restart (alternative)

Restart or reload service

systemctl restart haproxy

Restart HAProxy service

systemctl reload haproxy

Reload configuration without dropping connections

Configuration Management

haproxy -c -f /etc/haproxy/haproxy.cfg

Check configuration syntax

haproxy -c -f <config_file>

Validate custom config file

systemctl reload haproxy

Reload configuration without dropping connections

kill -USR2 $(cat /var/run/haproxy.pid)

Graceful reload via signal

haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid

Start HAProxy in daemon mode

haproxy -f /etc/haproxy/haproxy.cfg -c -V

Verbose configuration check

Runtime API - Socket Commands

echo "show info" | socat stdio /var/run/haproxy.sock

Display HAProxy information

echo "show stat" | socat stdio /var/run/haproxy.sock

Display statistics

echo "show servers state" | socat stdio /var/run/haproxy.sock

Display server states

echo "show pools" | socat stdio /var/run/haproxy.sock

Display memory pool information

echo "show sess" | socat stdio /var/run/haproxy.sock

Display current sessions

echo "show errors" | socat stdio /var/run/haproxy.sock

Display recent errors

echo "show table" | socat stdio /var/run/haproxy.sock

Display stick tables

Server Management

echo "disable server <backend>/<server>" | socat stdio /var/run/haproxy.sock

Disable backend server

echo "enable server <backend>/<server>" | socat stdio /var/run/haproxy.sock

Enable backend server

echo "set server <backend>/<server> state maint" | socat stdio /var/run/haproxy.sock

Set server to maintenance mode

echo "set server <backend>/<server> state ready" | socat stdio /var/run/haproxy.sock

Set server to ready state

echo "set server <backend>/<server> weight <weight>" | socat stdio /var/run/haproxy.sock

Change server weight

echo "show backend" | socat stdio /var/run/haproxy.sock

List all backends

Health Checks & Monitoring

echo "show health" | socat stdio /var/run/haproxy.sock

Display health check status

echo "show info" | socat stdio /var/run/haproxy.sock | grep -i uptime

Check HAProxy uptime

echo "show stat" | socat stdio /var/run/haproxy.sock | grep -v "^#"

Get backend statistics

echo "show pools" | socat stdio /var/run/haproxy.sock

Check memory pool usage

curl http://localhost:8080/haproxy?stats

Access stats page via HTTP

curl http://localhost:8080/haproxy?stats;csv

Get stats in CSV format

Session Management

echo "show sess" | socat stdio /var/run/haproxy.sock

Display all sessions

echo "show sess <id>" | socat stdio /var/run/haproxy.sock

Display specific session details

echo "shutdown session <id>" | socat stdio /var/run/haproxy.sock

Terminate specific session

echo "shutdown sessions server <backend>/<server>" | socat stdio /var/run/haproxy.sock

Shutdown all sessions on server

echo "show table <table>" | socat stdio /var-run/haproxy.sock

Display stick table entries

echo "clear table <table>" | socat stdio /var/run/haproxy.sock

Clear stick table

Rate Limiting & ACLs

echo "show acl" | socat stdio /var/run/haproxy.sock

List all ACLs

echo "show acl <id>" | socat stdio /var/run/haproxy.sock

Show specific ACL entries

echo "add acl <id> <pattern>" | socat stdio /var/run/haproxy.sock

Add ACL entry at runtime

echo "del acl <id> <pattern>" | socat stdio /var/run/haproxy.sock

Delete ACL entry

echo "clear acl <id>" | socat stdio /var/run/haproxy.sock

Clear all ACL entries

echo "show map" | socat stdio /var/run/haproxy.sock

List all maps

echo "set map <file> <key> <value>" | socat stdio /var/run/haproxy.sock

Update map entry

SSL/TLS Management

echo "show ssl cert" | socat stdio /var/run/haproxy.sock

List SSL certificates

echo "show ssl cert <file>" | socat stdio /var/run/haproxy.sock

Display certificate details

echo "set ssl cert <file> <payload>" | socat stdio /var/run/haproxy.sock

Update SSL certificate

echo "commit ssl cert <file>" | socat stdio /var/run/haproxy.sock

Commit certificate changes

echo "abort ssl cert <file>" | socat stdio /var/run/haproxy.sock

Abort certificate transaction

openssl s_client -connect localhost:443 -showcerts

Test SSL connection

Logging & Debugging

echo "show errors" | socat stdio /var/run/haproxy.sock

Display recent errors

echo "show events" | socat stdio /var/run/haproxy.sock

Display event log

tail -f /var/log/haproxy.log

Monitor HAProxy logs

haproxy -d -f /etc/haproxy/haproxy.cfg

Start in debug mode

echo "set maxconn global <value>" | socat stdio /var/run/haproxy.sock

Change global max connections

echo "show cli sockets" | socat stdio /var/run/haproxy.sock

Display CLI socket information

Performance Tuning

echo "show pools" | socat stdio /var/run/haproxy.sock

Display memory pool statistics

echo "show info" | socat stdio /var/run/haproxy.sock | grep conn

Check connection statistics

echo "set maxconn frontend <name> <value>" | socat stdio /var/run/haproxy.sock

Adjust frontend max connections

echo "set rate-limit connections global <value>" | socat stdio /var/run/haproxy.sock

Set global connection rate limit

echo "set rate-limit sessions global <value>" | socat stdio /var/run/haproxy.sock

Set global session rate limit

echo "show activity" | socat stdio /var/run/haproxy.sock

Display activity counters

Troubleshooting

haproxy -vv

Display verbose version and build options

echo "show info" | socat stdio /var/run/haproxy.sock

Display process information

echo "show proc" | socat stdio /var/run/haproxy.sock

Display process list

netstat -tuln | grep haproxy

Check HAProxy listening ports

ps aux | grep haproxy

Check HAProxy processes

lsof -i -P -n | grep haproxy

List HAProxy open connections

strace -p $(cat /var/run/haproxy.pid)

Trace system calls