watt42-panelview-template/run.sh

36 lines
755 B
Bash
Executable file

#!/usr/bin/env bash
echo "Starting the application..."
PORT=5050
# source .env file if it exists
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi
cleanup() {
echo "Stopping the application..."
pkill -f "panel serve main.py"
}
trap cleanup EXIT
poetry run panel serve main.py --port $PORT &
# if 'nc' is available, use it to check if the port is open
if ! command -v nc &> /dev/null
then
echo "'nc' command could not be found, please install it for better port checking."
sleep 2
else
# wait until port is open
while ! nc -z localhost $PORT; do
sleep 0.5
done
fi
poetry run python -m webbrowser http://localhost:$PORT
# wait until user kills the process (by hitting ctrl+c or otherwise)
wait