Last active
November 20, 2015 12:43
-
-
Save fredead/5ac1fe28f8059dbebc2f to your computer and use it in GitHub Desktop.
Timer based restart script while checking a process actually started
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# In general using this is a hack round another problem | |
#Sometimes it can be a practical answer to be productive rather than going in circles | |
while [ true ]; do | |
RENEW_TIME=60000 | |
CHECK_TIME=60 | |
# get my Lease for the | |
LEASE=`echo curl http://lease` | |
# get time of length of the lease | |
RENEW_TIME=60000 | |
# knock of random 10% ( note < 100 seconds will be 100seconds) | |
RENEW_TIME=$(($RENEW_TIME - ($RENEW_TIME / 100 * ($RANDOM % 10 )))) | |
if [ "'${APP_PID}'" != "''" ]; then | |
if [ "`ps -p ${APP_PID} | grep -v PID`" != "" ]; then | |
echo "Forcing death" | |
kill -9 $APP_PID | |
fi | |
fi | |
run-app $LEASE & | |
APP_PID=$! | |
# just make sure it is up in a expontional way | |
CHECK_COUNT=1 | |
while [ ${CHECK_TIME} -gt 0 ]; do | |
# is it running | |
sleep $CHECK_COUNT | |
# -e means will will exit here | |
kill -0 ${APP_PID} | |
CHECK_TIME=$(($CHECK_TIME - $CHECK_COUNT)) | |
CHECK_COUNT=$(($CHECK_COUNT + $CHECK_COUNT)) | |
done | |
sleep ${RENEW_TIME} | |
kill $APP_PID | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment