#!/bin/bash
# =====================================================
# stop.sh — Stop the Niscom Payroll backend
# =====================================================

PID_FILE=/home3/webniscom/payroll/payroll.pid

if [ ! -f "$PID_FILE" ]; then
    echo "PID file not found — app may not be running"
    exit 0
fi

PID=$(cat "$PID_FILE")

if kill -0 "$PID" 2>/dev/null; then
    kill "$PID"
    rm -f "$PID_FILE"
    echo "Stopped PID $PID"
else
    echo "Process $PID not running — cleaning up PID file"
    rm -f "$PID_FILE"
fi
