Created
November 10, 2015 15:49
-
-
Save sxd/850f20c0d0dd7a6b26c8 to your computer and use it in GitHub Desktop.
This file contains 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/sh | |
NAME_CACHE=$1 | |
function cache_activate { | |
RES=`touch /var/run/cache_activated` | |
if [ $? -eq 0 ]; then | |
RES=`varnishadm vcl.use $NAME_CACHE` | |
if [ $? -eq 0 ]; then | |
return 0; | |
else | |
return 1; | |
fi | |
else | |
return 2; | |
fi | |
return 1; | |
} | |
function cache_deactivate { | |
RES=`varnishadm vcl.use cache-home` | |
if [ $? -eq 0 ]; then | |
RES=`rm /var/run/cache_activated` | |
if [ $? -eq 0]; then | |
return 0; | |
else | |
return 1; | |
fi; | |
else | |
return 1; | |
fi | |
return 1; | |
} | |
function email_activate { | |
## Do some email work | |
} | |
function email_deactivate { | |
## Do some email work | |
} | |
function check_long_time { | |
BORN=`stat -c "%Z" /var/run/cache_activated` | |
if [ $? -ne 0 ]; then | |
return 0; | |
fi | |
CURRENT_DATE=`date +%s` | |
AGE=`echo $(( $CURRENT_DATE - $BORN ))` | |
if [ $AGE -gt 3600 ]; then | |
return 0; | |
fi | |
return -1; | |
} | |
function start_check { | |
while [ 1 ]; do | |
check_long_time | |
if [ $? -eq 0 ]; then | |
email_deactivate | |
cache_deactivate | |
exit | |
fi | |
sleep 3 | |
done | |
} | |
cache_activate | |
if [ $? -eq 0 ]; then | |
echo "Daemon start" | |
email_activate | |
start_check & | |
else | |
echo "Something wrong use -x" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment