Skip to main content

Survive a Proxy Node Failure

A single SafeSquid node is a single point of failure for every user behind it. When the proxy stops answering, browsing stops — and so does policy enforcement, logging, and the audit trail that proves enforcement happened. Users escalate, and the fastest workaround an impatient administrator reaches for is disabling the proxy entirely. Active-passive high availability removes that pressure. Clients connect to a virtual IP (VIP) that always points at a healthy node. Keepalived moves the VIP on failure in 2–3 seconds; Monit independently restarts a crashed SafeSquid process on either node.

Split responsibilities between two tools

Keepalived and Monit solve different problems. They do not conflict — running only one leaves a gap. Keepalived runs the health-check script every 5 seconds. If SafeSquid is not serving traffic, Keepalived drops the Master’s VRRP priority below the Backup’s and the VIP moves. Monit restarts SafeSquid on the failed node and logs the event.

Match the design to the failure

Prerequisites

  • Two SafeSquid instances installed and activated — one Master, one Backup.
  • Both nodes on the same subnet, so VRRP advertisements reach both.
  • One unused IP address for the VIP. It must not be assigned to any other host or DHCP pool.
  • Root or sudo access on both nodes.
  • Firewall rules permitting VRRP (IP protocol 112) between the two nodes.
  • keepalived, monit, and curl available from the distribution repositories.
Record the environment before you start. The examples below use these values — substitute your own throughout.
Point clients at the VIP, not at either node address. A PAC file, GPO, or MDM profile that names the Master directly will not fail over.

Install both packages on both nodes

Run this on the Master and the Backup:
Expected result: both services install and are available to systemctl.

Create the health-check script

Keepalived runs this script every 5 seconds. A non-zero exit drops the node’s VRRP priority and triggers VIP handover. Create /etc/keepalived/check_safesquid.sh on both nodes:
Make it executable on both nodes:
The second check matters. A process that is running but not accepting connections still fails users, and a PID check alone will not catch it.

Configure Keepalived on both nodes

Only state and priority differ between the two files. Everything else must match exactly.
virtual_router_id must be identical on both nodes, and auth_pass must be identical and 8 characters or fewer — Keepalived truncates longer values, which produces a silent mismatch and two Masters.
Write /etc/keepalived/keepalived.conf:

Why the weight is -101

The weight must push the Master’s effective priority below the Backup’s, not merely reduce it.
  • The Master starts at priority 101.
  • On check failure, weight -101 makes the effective priority 101 - 101 = 0.
  • 0 is below the Backup’s 100, so the Backup wins the VRRP election, advertises the higher priority, and the Master releases the VIP.
A weight of -60 yields 101 - 60 = 41. That is still below 100, but it does not reliably drive the BACKUP state transition across Keepalived versions. Use -101 so the outcome is unambiguous.

Configure Monit on both nodes

Monit supervises the SafeSquid process and restarts it. It does not touch the VIP — that stays with Keepalived. Write /etc/monit/conf.d/safesquid.monit on both nodes:
Keep set daemon and set httpd in /etc/monit/monitrc only. Repeating them here produces an address option specified twice error and Monit refuses to start.

Start both services

Run on both nodes:
Confirm the VIP landed on the Master:
Expected output on the Master only:
The proto keepalived tag confirms Keepalived owns the address and will withdraw it automatically on failover. An address without that tag was assigned statically and will not move.

Verify and evidence failover

Confirm the Master state and a passing health check:
Expected output on the Master includes:

Test the failover

Open two terminals. Watch the log on the Backup while you stop SafeSquid on the Master.
Within 10–15 seconds the log shows the handover:
Confirm the VIP moved:
Restore SafeSquid on the Master after the test:
nopreempt keeps the VIP on the Backup after the Master recovers. This avoids a second interruption during business hours. To move the VIP back deliberately, restart Keepalived on the Master: sudo systemctl restart keepalived.

Capture HA evidence

Store these artifacts with the change record:
  • Both keepalived.conf files and the health-check script, with a checksum.
  • journalctl -u keepalived extract covering the tested failover, showing the state transition and gratuitous ARP.
  • ip a output before and after failover, showing VIP ownership on each node.
  • /var/log/keepalived_check.log and /var/log/monit.log for the test window.
  • Client-side proof that browsing resumed through the VIP, plus the SafeSquid access log entries from the surviving node.
  • The date of the last tested failover and the named owner of the next test.
Untested failover is not high availability. Schedule a failover test on the same cadence as your disaster-recovery restore test and keep the evidence.

Troubleshoot HA failures

File reference

Master and Backup differences

Next steps