#!/bin/sh
set -eu
PID_FILE="/share/homes/mailcat/mailcat/run/mailcat.pid"
LOG_DIR="/share/homes/mailcat/mailcat/log"

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