mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-28 18:26:15 +01:00
5e0d8cb6dd
It looks like the plugin-server isn't shutting down cleanly, from looking at the logs. They abruptly stop. We have a trap to pick kill the yarn command on EXIT, however, yarn v1 doesn't propagate SIGTERM to subprocesses, hence node never recieves it. Separately it looks like the shutdown ends up being called multiple times which results in a force shutdown. I'm not entirely sure what is going on here but I'll leave that to another PR.
60 lines
1.3 KiB
Bash
Executable File
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="yarn start:dev" || cmd="node dist/index.js"
|
|
|
|
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
|
|
$cmd &
|
|
child=$!
|
|
wait $child
|
|
else
|
|
echo "🔁 Starting plugin server in a resiliency loop..."
|
|
while true; do
|
|
$cmd
|
|
echo "💥 Plugin server crashed!"
|
|
echo "⌛️ Waiting 2 seconds before restarting..."
|
|
sleep 2
|
|
done
|
|
fi
|