Files
netneutrality/startup.sh
T

53 lines
1.0 KiB
Bash

#!/bin/sh
prop() {
grep "${1}" bot.properties | cut -d'=' -f2
}
_term() {
echo "Caught SIGTERM/SIGINT signal, graceful shutdown of bot.."
if [ -z "$pid" ]; then
echo "Bot isn't running, exiting."
exit 0
else
/usr/bin/curl --no-progress-meter http://localhost:"$API_PORT"/actions/shutdown
echo "Waiting 2 seconds for bot shutdown"
sleep 2
fi
}
trap _term TERM
trap _term INT
if [ ! -f /usr/bin/nc ]; then
echo "nc not found. Exiting."
exit 1
fi
if [ -z $API_PORT ]; then
API_PORT=9000;
fi
if [ -z $MYSQL_HOST ]; then
MYSQL_HOST="$(prop 'MYSQL_HOST')"
fi
if [ -z $MYSQL_PORT ]; then
MYSQL_PORT=$(prop 'MYSQL_PORT')
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..";
/opt/java/openjdk/bin/java -jar /app/netneutrality-jar-with-dependencies.jar &
pid=$!
wait "$pid"
else
echo "No connection to database, shutting down.."
exit 1
fi