Skip to content

Instantly share code, notes, and snippets.

@zioproto
Last active November 25, 2022 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zioproto/a0617b36f74b6eca11a356045d9d185c to your computer and use it in GitHub Desktop.
Save zioproto/a0617b36f74b6eca11a356045d9d185c to your computer and use it in GitHub Desktop.
Restart Wordpress if it is serving HTTP 500s
#! /usr/bin/env python3
import requests
from requests.adapters import HTTPAdapter, Retry
import os
s = requests.Session()
retries = Retry(total=5,
backoff_factor=0.1,
status_forcelist=[ 500, 502, 503, 504 ])
s.mount('https://', HTTPAdapter(max_retries=retries))
r = s.head("https://blog.ninux.org")
if r.status_code == 500:
os.system("systemctl restart apache2")
os.system("systemctl restart mysql")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment