Files
sailing-analytics/java/target/stop
T

42 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
. `pwd`/env.sh
if [[ `uname` != "Darwin" ]]; then
TELNET_ACTIVE=`netstat -tlnp 2>/dev/null | grep ":$TELNET_PORT"`
else
TELNET_ACTIVE=`netstat -an 2>/dev/null | grep ".$TELNET_PORT"`
fi
if [[ $TELNET_PORT == "" ]] || [[ $TELNET_ACTIVE == "" ]]; then
echo "Could not find server on telnet port $TELNET_PORT. Perhaps server is not running?"
if [[ $SERVER_STARTUP_NOTIFY != "" ]]; then
echo "Stopped" | mail -s "Server $SERVER_NAME could not be stopped!" $SERVER_STARTUP_NOTIFY
fi
else
NC_CMD="nc -t 127.0.0.1 $TELNET_PORT"
echo shutdown | $NC_CMD
echo "Stopped server $SERVER_NAME"
if [[ $SERVER_STARTUP_NOTIFY != "" ]]; then
echo "OK" | mail -s "Server $SERVER_NAME stopped successfully!" $SERVER_STARTUP_NOTIFY
fi
fi
# Wait for server to die; if it doesn't, kill it after a timeout
KILL_TIMEOUT_IN_SECONDS=10
SERVER_PID=`cat server.pid`
seconds_counter=$KILL_TIMEOUT_IN_SECONDS
while ((seconds_counter-- != 0)); do
if [ ! -d /proc/$SERVER_PID ]; then
echo "Server successfully and gracefully stopped by OSGi shutdown command."
rm server.pid
exit 0
fi
sleep 1
done
echo "Server didn't die within ${KILL_TIMEOUT_IN_SECONDS}s after sending it the shutdown command. Killing..."
kill $SERVER_PID
rm server.pid