#!/bin/bash
DIR=$(dirname "$(readlink -f "$0")") || exit
COMMAND="$DIR/run $1"

echo $DIR $COMMAND

PIDFILE="$DIR/gitea.pid"
# echo $PIDFILE
# read -r PID < $PIDFILE
# echo PID $PID
# echo "$(ps -ea | grep $PID)"
if [ -e ${PIDFILE} ]; then
  read -r PID < $PIDFILE
  if (ps -ea | grep $PID); then
    echo "start aborted gitea is already running."
    exit 1;
  fi
fi

echo starting gitea sending log to gitea.log
$COMMAND > $DIR/gitea.log &
echo PID of gitea process is $!
echo $! > $PIDFILE