HAProxy Commands
HAProxy CLI commands and runtime API for load balancer management.
Service Startup Procedure
Step 1: Check configurationValidate config before starting
haproxy -c -f /etc/haproxy/haproxy.cfgCheck configuration syntax
Step 2: Start serviceStart HAProxy service
systemctl start haproxyStart HAProxy via systemd
Step 3: Verify serviceCheck service is running
systemctl status haproxyCheck HAProxy status
echo "show info" | socat stdio /var/run/haproxy.sockDisplay HAProxy information
Step 4: Check backendsVerify backend servers are up
echo "show servers state" | socat stdio /var/run/haproxy.sockDisplay server states
Service Shutdown Procedure
Step 1: Check active connectionsReview current sessions
echo "show sess" | socat stdio /var/run/haproxy.sockDisplay current sessions
Step 2: Drain connectionsOptionally drain before shutdown
echo "set server <backend>/<server> state drain" | socat stdio /var/run/haproxy.sockDrain server connections
Step 3: Stop serviceStop HAProxy service
systemctl stop haproxyStop HAProxy service
Step 4: Restart (alternative)Restart or reload service
systemctl restart haproxyRestart HAProxy service
systemctl reload haproxyReload configuration without dropping connections
Configuration Management
haproxy -c -f /etc/haproxy/haproxy.cfgCheck configuration syntax
haproxy -c -f <config_file>Validate custom config file
systemctl reload haproxyReload 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.pidStart HAProxy in daemon mode
haproxy -f /etc/haproxy/haproxy.cfg -c -VVerbose configuration check
Runtime API - Socket Commands
echo "show info" | socat stdio /var/run/haproxy.sockDisplay HAProxy information
echo "show stat" | socat stdio /var/run/haproxy.sockDisplay statistics
echo "show servers state" | socat stdio /var/run/haproxy.sockDisplay server states
echo "show pools" | socat stdio /var/run/haproxy.sockDisplay memory pool information
echo "show sess" | socat stdio /var/run/haproxy.sockDisplay current sessions
echo "show errors" | socat stdio /var/run/haproxy.sockDisplay recent errors
echo "show table" | socat stdio /var/run/haproxy.sockDisplay stick tables
Server Management
echo "disable server <backend>/<server>" | socat stdio /var/run/haproxy.sockDisable backend server
echo "enable server <backend>/<server>" | socat stdio /var/run/haproxy.sockEnable backend server
echo "set server <backend>/<server> state maint" | socat stdio /var/run/haproxy.sockSet server to maintenance mode
echo "set server <backend>/<server> state ready" | socat stdio /var/run/haproxy.sockSet server to ready state
echo "set server <backend>/<server> weight <weight>" | socat stdio /var/run/haproxy.sockChange server weight
echo "show backend" | socat stdio /var/run/haproxy.sockList all backends
Health Checks & Monitoring
echo "show health" | socat stdio /var/run/haproxy.sockDisplay health check status
echo "show info" | socat stdio /var/run/haproxy.sock | grep -i uptimeCheck HAProxy uptime
echo "show stat" | socat stdio /var/run/haproxy.sock | grep -v "^#"Get backend statistics
echo "show pools" | socat stdio /var/run/haproxy.sockCheck memory pool usage
curl http://localhost:8080/haproxy?statsAccess stats page via HTTP
curl http://localhost:8080/haproxy?stats;csvGet stats in CSV format
Session Management
echo "show sess" | socat stdio /var/run/haproxy.sockDisplay all sessions
echo "show sess <id>" | socat stdio /var/run/haproxy.sockDisplay specific session details
echo "shutdown session <id>" | socat stdio /var/run/haproxy.sockTerminate specific session
echo "shutdown sessions server <backend>/<server>" | socat stdio /var/run/haproxy.sockShutdown all sessions on server
echo "show table <table>" | socat stdio /var-run/haproxy.sockDisplay stick table entries
echo "clear table <table>" | socat stdio /var/run/haproxy.sockClear stick table
Rate Limiting & ACLs
echo "show acl" | socat stdio /var/run/haproxy.sockList all ACLs
echo "show acl <id>" | socat stdio /var/run/haproxy.sockShow specific ACL entries
echo "add acl <id> <pattern>" | socat stdio /var/run/haproxy.sockAdd ACL entry at runtime
echo "del acl <id> <pattern>" | socat stdio /var/run/haproxy.sockDelete ACL entry
echo "clear acl <id>" | socat stdio /var/run/haproxy.sockClear all ACL entries
echo "show map" | socat stdio /var/run/haproxy.sockList all maps
echo "set map <file> <key> <value>" | socat stdio /var/run/haproxy.sockUpdate map entry
SSL/TLS Management
echo "show ssl cert" | socat stdio /var/run/haproxy.sockList SSL certificates
echo "show ssl cert <file>" | socat stdio /var/run/haproxy.sockDisplay certificate details
echo "set ssl cert <file> <payload>" | socat stdio /var/run/haproxy.sockUpdate SSL certificate
echo "commit ssl cert <file>" | socat stdio /var/run/haproxy.sockCommit certificate changes
echo "abort ssl cert <file>" | socat stdio /var/run/haproxy.sockAbort certificate transaction
openssl s_client -connect localhost:443 -showcertsTest SSL connection
Logging & Debugging
echo "show errors" | socat stdio /var/run/haproxy.sockDisplay recent errors
echo "show events" | socat stdio /var/run/haproxy.sockDisplay event log
tail -f /var/log/haproxy.logMonitor HAProxy logs
haproxy -d -f /etc/haproxy/haproxy.cfgStart in debug mode
echo "set maxconn global <value>" | socat stdio /var/run/haproxy.sockChange global max connections
echo "show cli sockets" | socat stdio /var/run/haproxy.sockDisplay CLI socket information
Performance Tuning
echo "show pools" | socat stdio /var/run/haproxy.sockDisplay memory pool statistics
echo "show info" | socat stdio /var/run/haproxy.sock | grep connCheck connection statistics
echo "set maxconn frontend <name> <value>" | socat stdio /var/run/haproxy.sockAdjust frontend max connections
echo "set rate-limit connections global <value>" | socat stdio /var/run/haproxy.sockSet global connection rate limit
echo "set rate-limit sessions global <value>" | socat stdio /var/run/haproxy.sockSet global session rate limit
echo "show activity" | socat stdio /var/run/haproxy.sockDisplay activity counters
Troubleshooting
haproxy -vvDisplay verbose version and build options
echo "show info" | socat stdio /var/run/haproxy.sockDisplay process information
echo "show proc" | socat stdio /var/run/haproxy.sockDisplay process list
netstat -tuln | grep haproxyCheck HAProxy listening ports
ps aux | grep haproxyCheck HAProxy processes
lsof -i -P -n | grep haproxyList HAProxy open connections
strace -p $(cat /var/run/haproxy.pid)Trace system calls