2013-02-19 01:00:54 +01:00
|
|
|
#!/usr/bin/env python
|
2013-01-31 16:49:09 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import pylibmc
|
|
|
|
import traceback
|
2013-03-13 19:26:51 +01:00
|
|
|
import logging
|
2013-04-18 22:58:32 +02:00
|
|
|
import time
|
2013-03-13 19:26:51 +01:00
|
|
|
|
|
|
|
logging.basicConfig(format="%(asctime)s restart-server: %(message)s",
|
|
|
|
level=logging.INFO)
|
2013-01-31 16:49:09 +01:00
|
|
|
|
|
|
|
# Color codes
|
|
|
|
OKBLUE = '\033[94m'
|
|
|
|
OKGREEN = '\033[92m'
|
|
|
|
WARNING = '\033[93m'
|
|
|
|
FAIL = '\033[91m'
|
|
|
|
ENDC = '\033[0m'
|
|
|
|
|
2013-04-09 21:51:16 +02:00
|
|
|
os.chdir("/home/humbug/humbug-deployments/current")
|
2013-01-31 16:49:09 +01:00
|
|
|
|
2013-04-18 22:58:32 +02:00
|
|
|
# Send a statsd event on restarting the server
|
2013-04-19 04:08:33 +02:00
|
|
|
subprocess.check_call(["python", "./manage.py", "send_stats", "incr", "events.server_restart", str(int(time.time()))])
|
2013-04-18 22:58:32 +02:00
|
|
|
|
2013-01-31 16:49:09 +01:00
|
|
|
# Restart the FastCGI process, which is running in a shell loop in screen.
|
|
|
|
# TODO: real daemonization
|
2013-03-13 19:26:51 +01:00
|
|
|
logging.info("Killing daemons")
|
2013-05-10 15:41:49 +02:00
|
|
|
for cmd in ('runfcgi', 'runtornado', "process_user_activity", "subscribe_new_users", "send_confirmation_emails", "send_missedmessage_reminders"):
|
2013-01-31 16:49:09 +01:00
|
|
|
try:
|
2013-04-12 21:34:58 +02:00
|
|
|
subprocess.check_call(["pkill", "-f", "manage.py " + cmd])
|
2013-01-31 16:49:09 +01:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
print "%sCould not kill %s; is it running?%s" % (WARNING, cmd, ENDC)
|
|
|
|
|
2013-03-13 19:26:51 +01:00
|
|
|
logging.info("Flushing memcached")
|
2013-03-04 16:54:21 +01:00
|
|
|
try:
|
|
|
|
if not pylibmc.Client(['127.0.0.1']).flush_all():
|
|
|
|
print "%sflush_all returned False%s" % (WARNING, ENDC)
|
|
|
|
# There doesn't seem to be a method to close a pylibmc Client object.
|
|
|
|
except:
|
|
|
|
print "%sCould not flush cache:%s" % (WARNING, ENDC)
|
|
|
|
traceback.print_exc()
|
|
|
|
|
2013-03-13 19:26:51 +01:00
|
|
|
logging.info("Refilling memcached caches")
|
2013-04-16 22:58:49 +02:00
|
|
|
subprocess.check_call(["python", "./manage.py", "fill_memcached_caches"])
|
2013-03-13 19:11:35 +01:00
|
|
|
|
2013-03-13 19:26:51 +01:00
|
|
|
logging.info("Done!")
|
2013-01-31 16:49:09 +01:00
|
|
|
print OKGREEN + "Application restarted successfully!" + ENDC
|