Sure, fairly straightforward test and restart.
I run this every 2 minutes in a cron job:
grommunio:~ # cat /etc/cron.d/gromox-http-watchdog
*/2 * * * * root /usr/local/sbin/gromox-http-watchdog.sh >/dev/null 2>&1
The script:
`
#!/bin/bash
set -euo pipefail
URL='http://127.0.0.1:10080/EWS/Exchange.asmx'
LOCK='/run/gromox-http-watch.lock'
LOGFILE='/var/log/gromox-http-watchdog.log'
mkdir -p /var/log
touch "$LOGFILE"
chmod 0644 "$LOGFILE"
exec >>"$LOGFILE" 2>&1
log() {
printf '[%s] %s\n' "$(date -Is)" "$*"
}
probe() {
curl -sS -o /dev/null -w "HTTP=%{http_code} TIME=%{time_total}\n" --max-time 10 "$URL" 2>/dev/null || true
}
exec 9>"$LOCK"
flock -n 9 || exit 0
result="$(probe)"
if [[ "$result" == HTTP=405* ]]; then
exit 0
fi
log "probe failed: $result; restarting gromox-http"
systemctl restart gromox-http.service
for _ in $(seq 1 30); do
sleep 5
result="$(probe)"
if [[ "$result" == HTTP=405* ]]; then
log "service recovered: $result"
exit 0
fi
done
log "service did not recover after restart"
exit 1
`