36 lines
824 B
Bash
36 lines
824 B
Bash
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
BASE_DIR="$(cd "$(dirname "$0")"/.. && pwd)"
|
|
LOG_DIR="$BASE_DIR/logs"
|
|
zero_pid="$LOG_DIR/zero_code.pid"
|
|
api_pid="$LOG_DIR/api_service.pid"
|
|
|
|
ret=1
|
|
if [ -f "$zero_pid" ]; then
|
|
kill "$(cat "$zero_pid")" || true
|
|
rm -f "$zero_pid"
|
|
ret=0
|
|
fi
|
|
if [ -f "$api_pid" ]; then
|
|
kill "$(cat "$api_pid")" || true
|
|
rm -f "$api_pid"
|
|
ret=0
|
|
fi
|
|
|
|
if [ $ret -eq 0 ]; then
|
|
echo stopped
|
|
exit 0
|
|
fi
|
|
|
|
ZERO_PORT="${ZERO_PORT:-8000}"
|
|
API_PORT="$(grep -oE '"port"\s*:\s*"?[0-9]+' "$BASE_DIR/ZeroCodeProject/apis/ZeroCodeMain/api_django.json" | grep -oE '[0-9]+' | head -n1)"
|
|
if command -v lsof >/dev/null 2>&1; then
|
|
p1="$(lsof -ti :"$ZERO_PORT" || true)"
|
|
p2="$(lsof -ti :"$API_PORT" || true)"
|
|
[ -n "$p1" ] && kill "$p1" || true
|
|
[ -n "$p2" ] && kill "$p2" || true
|
|
echo stopped
|
|
exit 0
|
|
fi
|
|
echo not running |