Skip to main content

Supervise SafeSquid Processes With Monit

Monit automatically monitors SafeSquid and restarts it if it crashes or becomes unresponsive. It also performs housekeeping tasks like log rotation and temporary file cleanup. Why you need this: Without Monit, a SafeSquid crash requires manual intervention. In production, this means downtime until someone notices and restarts the service.

Prerequisites

:::note Before You Start
  • Linux host with systemd
  • Root or sudo access
  • SafeSquid installed and running
  • Log storage capacity for Monit logs
:::

Installation and Configuration

1. Install Monit

Debian/Ubuntu:
RHEL/Rocky/CentOS:
Verify installation:
Expected result: This is Monit version 5.34.3 (the number varies by release), followed by the build options.

2. Enable Monit Service

Expected result: systemctl is-active monit prints active and systemctl is-enabled monit prints enabled.

3. Configure Monit HTTP Interface (Local Only)

Edit /etc/monit/monitrc:
Add or uncomment:
Save and reload:
Verify:
Expected result: the first line of an HTML page that starts with <!DOCTYPE html> and contains the title Monit: followed by the hostname.

4. Add SafeSquid Process and Port Checks

Create /etc/monit/conf.d/safesquid:
Add:
Explanation:
  • Monitors SafeSquid process via PID file
  • Checks port 8080 for HTTP responsiveness
  • Auto-restarts if port check fails
  • Alerts if SafeSquid restarts 3+ times in 5 cycles (possible persistent issue)
Reload and verify:
Expected result: status shows Running and OK.

5. Add Housekeeping Checks

Log Rotation Trigger: Create /etc/monit/conf.d/safesquid-logs:
Add:
Temporary Files Cleanup: Add to the same file:
:::caution Cleanup Script Risk The temp file cleanup example deletes files older than 1 day in /tmp. Adjust the path and age to match your environment to avoid deleting needed files. ::: Reload:

6. Add Update Orchestration (Optional)

If you want Monit to trigger SafeSquid upgrades when an upgrade flag file appears: Create /etc/monit/conf.d/safesquid-upgrade:
Add:
Note: You’ll need to create the /usr/local/bin/safesquid-upgrade script separately.

7. Reload and Validate All Checks

Expected:
  • monit summary shows all checks
  • monit status shows all checks as Running and OK

Verify Monit is Working

Test Auto-Restart

Simulate SafeSquid crash:
Wait 1-2 minutes (one Monit check cycle), then check:
Expected: SafeSquid is running again (Monit restarted it automatically). Check Monit logs:
Expected log entries:

View Monit Dashboard

From the SafeSquid server:
Or open in a browser on the server (if GUI available): http://localhost:2812 Expected: Monit dashboard showing SafeSquid status as green/running.

Troubleshooting

Still not working?
  1. Check Monit configuration syntax:
    Should return: Control file syntax OK
  2. Check Monit logs:
  3. Verify SafeSquid PID file location:
    If PID file doesn’t exist, update the Monit check to use process name instead.

Source register


Next Steps

  1. BIND - Configure local DNS resolver
  2. NTP - Ensure accurate time synchronization
  3. Audit & Forensics - Monitor SafeSquid logs and events