Files
zulip/tools/restart-server
Luke Faraone 7b75dd9cc4 Use different mechanism to determine the running user
Per http://docs.python.org/2/library/os.html#os.getlogin, getlogin()
only works when you have an associated controlling tty.

This script didn't work previously because when we do deployments there
is no tty. Thus, we switch to the alternative mechanism for determining
the current username described on the page linked above.

(imported from commit 1dbcf98fd7248d20e501fd7fb22e1dbd306040fd)
2013-06-19 16:35:35 -04:00

46 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python
import os
import sys
import pwd
import subprocess
import pylibmc
import traceback
import logging
import time
from humbug_tools import ENDC, WARNING, OKGREEN, DEPLOYMENTS_DIR
logging.basicConfig(format="%(asctime)s restart-server: %(message)s",
level=logging.INFO)
deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
os.chdir(deploy_path)
if os.path.exists("/etc/humbug-server"):
with open("/etc/humbug-machinetype") as mtf:
if pwd.getpwuid(os.getuid())[0] != "humbug":
logging.error("Must be run as user 'humbug'.")
sys.exit(1)
# Send a statsd event on restarting the server
subprocess.check_call(["python", "./manage.py", "send_stats", "incr", "events.server_restart", str(int(time.time()))])
logging.info("Filling memcached caches")
subprocess.check_call(["python", "./manage.py", "fill_memcached_caches"])
# Restart the FastCGI and related processes via supervisorctl. We
# minimize downtime by restarting Django and Tornado separately from
# the other worker processes.
logging.info("Killing daemons")
subprocess.check_call(["supervisorctl", "stop", "humbug-workers:*"])
subprocess.check_call(["supervisorctl", "stop", "humbug-django"])
subprocess.check_call(["supervisorctl", "stop", "humbug-tornado"])
subprocess.check_call(["ln", '-nsf', deploy_path, os.path.join(DEPLOYMENTS_DIR, "current")])
subprocess.check_call(["supervisorctl", "start", "humbug-tornado"])
subprocess.check_call(["supervisorctl", "start", "humbug-django"])
subprocess.check_call(["supervisorctl", "start", "humbug-workers:*"])
logging.info("Done!")
print OKGREEN + "Application restarted successfully!" + ENDC