Created
March 6, 2015 06:46
-
-
Save y16ra/cc37f23dbe94ea700b42 to your computer and use it in GitHub Desktop.
nginx上のproxy cache をpurgeするスクリプト。(http://monasan.info/blog/用)
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
#!/usr/bin/env python | |
import os | |
import commands | |
# logging config | |
from logging import getLogger,StreamHandler,Formatter,DEBUG | |
logger = getLogger(__name__) | |
handler = StreamHandler() | |
handler.setLevel(DEBUG) | |
handler.setFormatter(Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) | |
logger.setLevel(DEBUG) | |
logger.addHandler(handler) | |
# search top page cache | |
cache_file_path = commands.getoutput("find /var/run/nginx-cache -type f -exec grep -l \"KEY: http://monasan.info/blog/$\" {} \;") | |
logger.debug("top page cache file : " + cache_file_path) | |
if os.path.exists(cache_file_path): | |
os.remove(cache_file_path) | |
logger.info(cache_file_path + " deleted.") | |
else: | |
logger.info("cache file not found.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment