0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-22 08:40:03 +01:00
posthog/bin/plugin-server

60 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "USAGE:"
echo " bin/plugin-server [FLAGS]"
echo " "
echo "FLAGS:"
echo " -h, --help Print this help information."
echo " --no-restart-loop Run without restart loop. Recommended when deferring resiliency to e.g. docker-compose."
exit 0
;;
--no-restart-loop)
NO_RESTART_LOOP='true'
shift
;;
*)
break
;;
esac
done
export BASE_DIR=$(dirname $(dirname "$PWD/${0#./}"))
export KAFKA_URL=${KAFKA_URL:-'kafka://kafka:9092'}
export KAFKA_HOSTS
./bin/migrate-check
cd plugin-server
if [[ -n $DEBUG ]]; then
echo "🧐 Verifying installed packages..."
yarn --frozen-lockfile
fi
if [ $? -ne 0 ]; then
echo "💥 Verification failed!"
exit 1
fi
[[ -n $DEBUG ]] && cmd=start:dev || cmd=start:dist
if [[ -n $NO_RESTART_LOOP ]]; then
echo "▶️ Starting plugin server..."
trap 'kill -TERM $child 2>/dev/null; while kill -0 $child 2>/dev/null; do sleep 1; done' EXIT
yarn $cmd &
child=$!
wait $child
else
echo "🔁 Starting plugin server in a resiliency loop..."
while true; do
yarn $cmd
echo "💥 Plugin server crashed!"
echo "⌛️ Waiting 2 seconds before restarting..."
sleep 2
done
fi