2013-10-31 16:56:06 +01:00
|
|
|
#!/usr/bin/python -u
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import logging
|
|
|
|
import datetime
|
|
|
|
import shutil
|
|
|
|
import time
|
|
|
|
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, TIMESTAMP_FORMAT, FAIL, WARNING, ENDC
|
|
|
|
|
|
|
|
logging.basicConfig(format="%(asctime)s upgrade-zulip: %(message)s",
|
|
|
|
level=logging.INFO)
|
|
|
|
|
|
|
|
if len(sys.argv) != 2:
|
|
|
|
print FAIL + "Usage: %s <tarball>" % (sys.argv[0],) + ENDC
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
tarball_path = sys.argv[1]
|
|
|
|
|
|
|
|
start_time = time.time()
|
|
|
|
got_lock = False
|
|
|
|
while time.time() - start_time < 300:
|
|
|
|
try:
|
|
|
|
os.mkdir(LOCK_DIR)
|
|
|
|
got_lock = True
|
|
|
|
break
|
|
|
|
except OSError:
|
|
|
|
print WARNING + "Another deployment in progress; waiting for lock..." + ENDC
|
|
|
|
time.sleep(10)
|
|
|
|
|
|
|
|
if not got_lock:
|
|
|
|
print FAIL + "Deployment already in progress. Please run\n" \
|
|
|
|
+ " %s/current/scripts/upgrade-zulip %s\n" % (DEPLOYMENTS_DIR, tarball_path) \
|
|
|
|
+ "manually when the previous deployment finishes, or run\n" \
|
|
|
|
+ " rmdir %s\n" % (LOCK_DIR,) \
|
|
|
|
+ "if the previous deployment crashed." \
|
|
|
|
+ ENDC
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT)
|
|
|
|
deploy_path = os.path.join(DEPLOYMENTS_DIR, timestamp)
|
|
|
|
|
|
|
|
logging.info("Unpacking the tarball")
|
2013-11-08 22:41:12 +01:00
|
|
|
deploy_path = subprocess.check_output([os.path.join(os.path.dirname(__file__), 'unpack-zulip'),
|
|
|
|
tarball_path])
|
|
|
|
os.chdir(deploy_path.strip())
|
2013-10-31 16:56:06 +01:00
|
|
|
|
|
|
|
logging.info("Restarting server...")
|
2013-11-08 22:41:12 +01:00
|
|
|
subprocess.check_output(["./scripts/restart-server"])
|
2013-10-31 16:56:06 +01:00
|
|
|
|
|
|
|
logging.info("Deployment complete")
|
|
|
|
shutil.rmtree(LOCK_DIR)
|