#!/bin/bash LOCKFILE="/var/mail-state/lib-postfix/master.lock" function log() { echo "[health] $@" } if [ -f "$LOCKFILE" ]; then PID=$(cat "$LOCKFILE") log "pid $PID" if kill -0 "$PID" 2>/dev/null; then if ss --listening --tcp | grep -P 'LISTEN.+:smtp' > /dev/null; then log "successfully listening to smtp" exit 0 fi else # Not our postfix lock. exit 0 fi fi log "bad health state" exit 1