Created
May 29, 2015 09:53
-
-
Save tianzhi0549/82d5c072e187cc9b8a1c to your computer and use it in GitHub Desktop.
Restart php-fpm when nginx returns status 502.
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
import httplib2, os, time | |
def getCurTime(): | |
return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) | |
def logging(str): | |
file=open("nginx502.log", "w") | |
file.writelines(str) | |
file.close() | |
h = httplib2.Http(".cache") | |
restartCmd="/etc/init.d/php-fpm restart" | |
while True: | |
(resp_headers, content) = h.request("http://codepp.net/", headers={'cache-control':'no-cache'}) | |
if resp_headers["status"]=="502": | |
logging("[{0}] encounter 502, execute {1}.\n".format(getCurTime(), restartCmd)) | |
os.system(restartCmd) | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment