restart-server: Add some output on what's happening as we go.

restart-server has been relatively slow recently, and it'd be nice to
know what it is spending its time doing when it hangs for a few
seconds.

(imported from commit a411c951f5a3f2a1366b6d5d3a40d0660ebec11b)
This commit is contained in:
Tim Abbott 2013-03-13 14:26:51 -04:00
parent 76837ebe2c
commit c0d65124f8
1 changed files with 10 additions and 0 deletions

View File

@ -4,6 +4,10 @@ import sys
import subprocess import subprocess
import pylibmc import pylibmc
import traceback import traceback
import logging
logging.basicConfig(format="%(asctime)s restart-server: %(message)s",
level=logging.INFO)
# Color codes # Color codes
OKBLUE = '\033[94m' OKBLUE = '\033[94m'
@ -17,19 +21,23 @@ os.chdir("/home/humbug/humbug")
#subprocess.check_call(["python", "manage.py", "syncdb"], stdout=open('/dev/null', 'w')) #subprocess.check_call(["python", "manage.py", "syncdb"], stdout=open('/dev/null', 'w'))
# Delete all .pyc files to avoid old module files hanging around # Delete all .pyc files to avoid old module files hanging around
logging.info("Starting restart process")
subprocess.check_call(["find", ".", "-name", "*.pyc", "-delete"], stdout=open('/dev/null', 'w')) subprocess.check_call(["find", ".", "-name", "*.pyc", "-delete"], stdout=open('/dev/null', 'w'))
# Update static files # Update static files
logging.info("Updating static files")
subprocess.check_call(["./tools/update-prod-static"]) subprocess.check_call(["./tools/update-prod-static"])
# Restart the FastCGI process, which is running in a shell loop in screen. # Restart the FastCGI process, which is running in a shell loop in screen.
# TODO: real daemonization # TODO: real daemonization
logging.info("Killing daemons")
for cmd in ('runfcgi', 'runtornado', "process_user_activity"): for cmd in ('runfcgi', 'runtornado', "process_user_activity"):
try: try:
subprocess.check_call(["pkill", "-f", "python manage.py " + cmd]) subprocess.check_call(["pkill", "-f", "python manage.py " + cmd])
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
print "%sCould not kill %s; is it running?%s" % (WARNING, cmd, ENDC) print "%sCould not kill %s; is it running?%s" % (WARNING, cmd, ENDC)
logging.info("Flushing memcached")
try: try:
if not pylibmc.Client(['127.0.0.1']).flush_all(): if not pylibmc.Client(['127.0.0.1']).flush_all():
print "%sflush_all returned False%s" % (WARNING, ENDC) print "%sflush_all returned False%s" % (WARNING, ENDC)
@ -38,7 +46,9 @@ except:
print "%sCould not flush cache:%s" % (WARNING, ENDC) print "%sCould not flush cache:%s" % (WARNING, ENDC)
traceback.print_exc() traceback.print_exc()
logging.info("Refilling memcached caches")
subprocess.check_call(["python", os.path.join(os.path.dirname(__file__), "..", "manage.py"), subprocess.check_call(["python", os.path.join(os.path.dirname(__file__), "..", "manage.py"),
"fill_memcached_caches"]) "fill_memcached_caches"])
logging.info("Done!")
print OKGREEN + "Application restarted successfully!" + ENDC print OKGREEN + "Application restarted successfully!" + ENDC