gitea/scripts/stop

25 lines
701 B
Bash
Executable File

#!/bin/bash
[[ ! $GITEA_DIR ]] && export GITEA_DIR=$(dirname $(cd $(dirname $(readlink -f $BASH_SOURCE));pwd -P))
PIDFILE="$GITEA_DIR/gitea.pid"
if [ ! -e ${PIDFILE} ]; then
echo "can't find PID file $PIDFILE process state unknown"
exit 1;
fi
read -r PID < $PIDFILE
if ( ! ps -ea | grep $PID ) &> /dev/null; then
echo "gitea is not running. ignoring stop request"
exit 0;
fi
CHILD_PIDS=$(pgrep -P $PID);
echo stopping gitea - kill processes $PID $CHILD_PIDS
kill $PID 2> /dev/null || echo Killing process failed, not running?
# Wait half a second and Kill child PIDs to be sure they are gone.
sleep 0.5
kill $CHILD_PIDS 2> /dev/null
rm $PIDFILE
# sleep 2
# echo "$(ps -faux | grep gitea)"