Skip to content

Instantly share code, notes, and snippets.

@andrewconner
Created June 20, 2013 16:21
Show Gist options
  • Save andrewconner/5824253 to your computer and use it in GitHub Desktop.
Save andrewconner/5824253 to your computer and use it in GitHub Desktop.
Killing a running Play! framework application. First gracefully, and then quite violently.
maxShutdownTime=15
function stopServiceProcess {
kill $pid || return 1
for ((i=0; i<maxShutdownTime*10; i++)); do
checkProcessIsRunning $pid
if [ $? -ne 0 ]; then
rm -f $pidFile
return 0
fi
sleep 0.1
done
echo -e "\n$serviceName did not terminate within $maxShutdownTime seconds, sending SIGKILL..."
kill -s KILL $pid || return 1
local killWaitTime=15
for ((i=0; i<killWaitTime*10; i++)); do
checkProcessIsRunning $pid
if [ $? -ne 0 ]; then
rm -f $pidFile
return 0
fi
sleep 0.1
done
echo "Error: $serviceName could not be stopped within $maxShutdownTime+$killWaitTime seconds!"
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment