Replaced the `curl` HTTP shutdown call with a `kill -TERM` signal to ensure the JVM shutdown hook executes cleanly. Added a `wait` command to block until the process finishes, enabling a more reliable and proper termination process.
48 lines
1.1 KiB
Bash
48 lines
1.1 KiB
Bash
#!/bin/sh
|
|
|
|
_term() {
|
|
echo "Caught SIGTERM/SIGINT signal, graceful shutdown of bot.."
|
|
if [ -z "$pid" ]; then
|
|
echo "Bot isn't running, exiting."
|
|
exit 0
|
|
else
|
|
# SIGTERM triggers the JVM shutdown hook (App.shutdown); wait until it has finished.
|
|
kill -TERM "$pid" 2>/dev/null
|
|
wait "$pid"
|
|
exit $?
|
|
fi
|
|
}
|
|
|
|
trap _term TERM
|
|
trap _term INT
|
|
|
|
API_PORT="${API_PORT:-9000}"
|
|
MYSQL_HOST="${MYSQL_HOST:-localhost}"
|
|
MYSQL_PORT="${MYSQL_PORT:-3306}"
|
|
MYSQL_DATABASE="${MYSQL_DATABASE:-netneutrality}"
|
|
|
|
if [ ! -f /usr/bin/nc ]; then
|
|
echo "nc not found. Exiting."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Waiting 10 seconds for database to start.."
|
|
sleep 10
|
|
|
|
echo "Checking if MySQL / MariaDB is started.."
|
|
if /usr/bin/nc -z $MYSQL_HOST $MYSQL_PORT; then
|
|
echo "Database OK. Starting bot..";
|
|
|
|
export FLYWAY_URL="jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}"
|
|
export FLYWAY_USER="${MYSQL_USER}"
|
|
export FLYWAY_PASSWORD="${MYSQL_PASSWORD}"
|
|
|
|
/opt/java/openjdk/bin/java -jar /app/netneutrality.jar &
|
|
|
|
pid=$!
|
|
wait "$pid"
|
|
else
|
|
echo "No connection to database, shutting down.."
|
|
exit 1
|
|
fi
|