#!/bin/bash
cd /home/z/my-project
while true; do
  if ! ss -tlnp | grep -q ":3000 "; then
    echo "[$(date)] Starting..." >> /home/z/my-project/dev.log
    node node_modules/.bin/next dev -p 3000 -H 0.0.0.0 >> /home/z/my-project/dev.log 2>&1
    EXIT=$?
    echo "[$(date)] Exited with code $EXIT. Restarting in 3s..." >> /home/z/my-project/dev.log
    sleep 3
  else
    sleep 5
  fi
done
