#!/bin/sh
set -eu
WEB_PID_FILE="/share/homes/mailcat/mailcat/run/mailcat_web.pid"
WEB_HOST="0.0.0.0"
WEB_PORT="4321"
LOG_DIR="/share/homes/mailcat/mailcat/log"

if [ -f "$WEB_PID_FILE" ]; then
  pid=""
  IFS= read -r pid < "$WEB_PID_FILE" || true
  if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
    echo "mailcat web running: $pid"
    echo "url: http://$WEB_HOST:$WEB_PORT/"
    exit 0
  fi
  echo "mailcat web not running: stale pid file ($pid)"
  exit 1
fi
echo "mailcat web not running"
echo "logs: $LOG_DIR/web.out"
exit 1
