#!/usr/bin/env bash
set -euo pipefail

APP="/home/pondoksy/amal.pondoksyarifuddin.com/app"   # <-- confirm this path
LOG="/home/pondoksy/amal.pondoksyarifuddin.com/nohup.out"
PID="/home/pondoksy/amal.pondoksyarifuddin.com/app.pid"

# Already running?
if pgrep -f "$APP" >/dev/null 2>&1; then
  echo "udah di-run" > ./out_test.txt
  exit 0
fi

# Ensure executable
[[ -x "$APP" ]] || chmod +x "$APP"

# Start in background, capture PID, and log output
nohup "$APP" >> "$LOG" 2>&1 &
echo $! > "$PID"
echo "baru running" > ./out_test.txt
