Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 64 lines (52 sloc) 1.496 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#!/bin/bash
# The logic to stop your application should be put in this script.

# debug
# set -x

#loads VERSION, DEPS_PARAMS, ID, LOG_FILE, PLAY_COMMAND="${OPENSHIFT_DATA_DIR}play-${VERSION}/play"
. ${OPENSHIFT_REPO_DIR}.openshift/action_hooks/load_config

if [[ ! $? -eq 0 ]]; then
exit $?
fi

#kill play if it was running
if [[ -f "server.pid" ]]; then

if [[ ! -f $PLAY_COMMAND ]]; then
echo "Error: couldn't find play executable at $PLAY_COMMAND"
exit 1
fi

echo "Stopping play application"
bash -c "$PLAY_COMMAND stop &> $LOG_FILE" &> /dev/null

#manually remove server.pid if it's there
if [[ -f "server.pid" ]]; then
echo "Manually removing server.pid file"
bash -c "rm server.pid &> $LOG_FILE" &> /dev/null
fi
fi

#it survived, try to kill it manually
if [[ -n `ps -A | grep ' java$'` ]]; then

# try 5 times to kill it
for c in `seq 1 5`; do
echo "Trying to kill java proccess, attemp number $c"
bash -c "pkill java &> $LOG_FILE" &> /dev/null
sleep $c
#killed it
if [[ -z `ps -A | grep ' java$'` ]]; then
exit 0
fi
done

# try 5 times to kill it
for c in `seq 1 5`; do
echo "Trying to kill java proccess with -SIGKILL, attemp number $c"
bash -c "pkill -SIGKILL java &> $LOG_FILE" &> /dev/null
sleep $c
#killed it
if [[ -z `ps -A | grep ' java$'` ]]; then
exit 0
fi
done

#couldn't kill it
if [[ -n `ps -A | grep ' java$'` ]]; then
echo "Error: could not stop play application, error executing 'pkill java'"
exit 1
fi
fi

exit 0
Something went wrong with that request. Please try again.