2013-02-19 01:00:54 +01:00
|
|
|
#!/usr/bin/env python
|
2013-01-31 16:49:09 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2013-06-19 21:16:39 +02:00
|
|
|
import pwd
|
2013-01-31 16:49:09 +01:00
|
|
|
import subprocess
|
2013-03-13 19:26:51 +01:00
|
|
|
import logging
|
2013-04-18 22:58:32 +02:00
|
|
|
import time
|
2013-06-27 20:03:51 +02:00
|
|
|
from humbug_tools import ENDC, OKGREEN, DEPLOYMENTS_DIR
|
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
|
|
|
|
2013-06-03 19:29:52 +02:00
|
|
|
deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
os.chdir(deploy_path)
|
2013-01-31 16:49:09 +01:00
|
|
|
|
2013-06-19 17:25:42 +02:00
|
|
|
if os.path.exists("/etc/humbug-server"):
|
|
|
|
with open("/etc/humbug-machinetype") as mtf:
|
2013-06-19 21:16:39 +02:00
|
|
|
if pwd.getpwuid(os.getuid())[0] != "humbug":
|
2013-06-19 17:25:42 +02:00
|
|
|
logging.error("Must be run as user 'humbug'.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
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-05-30 21:05:34 +02:00
|
|
|
logging.info("Filling memcached caches")
|
|
|
|
subprocess.check_call(["python", "./manage.py", "fill_memcached_caches"])
|
|
|
|
|
2013-05-21 21:21:53 +02:00
|
|
|
# Restart the FastCGI and related processes via supervisorctl. We
|
|
|
|
# minimize downtime by restarting Django and Tornado separately from
|
|
|
|
# the other worker processes.
|
2013-03-13 19:26:51 +01:00
|
|
|
logging.info("Killing daemons")
|
2013-05-21 21:21:53 +02:00
|
|
|
subprocess.check_call(["supervisorctl", "stop", "humbug-workers:*"])
|
2013-05-23 00:04:00 +02:00
|
|
|
subprocess.check_call(["supervisorctl", "stop", "humbug-django"])
|
2013-06-13 22:22:22 +02:00
|
|
|
subprocess.check_call(["supervisorctl", "stop", "humbug-tornado"])
|
2013-06-03 19:29:52 +02:00
|
|
|
|
|
|
|
subprocess.check_call(["ln", '-nsf', deploy_path, os.path.join(DEPLOYMENTS_DIR, "current")])
|
|
|
|
|
2013-06-13 22:22:22 +02:00
|
|
|
subprocess.check_call(["supervisorctl", "start", "humbug-tornado"])
|
2013-05-23 00:04:00 +02:00
|
|
|
subprocess.check_call(["supervisorctl", "start", "humbug-django"])
|
2013-05-21 21:21:53 +02:00
|
|
|
subprocess.check_call(["supervisorctl", "start", "humbug-workers:*"])
|
2013-01-31 16:49:09 +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
|