Skip to content

Instantly share code, notes, and snippets.

@tianzhi0549
Created May 29, 2015 09:53
Show Gist options
  • Save tianzhi0549/82d5c072e187cc9b8a1c to your computer and use it in GitHub Desktop.
Save tianzhi0549/82d5c072e187cc9b8a1c to your computer and use it in GitHub Desktop.
Restart php-fpm when nginx returns status 502.
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