mirror of https://github.com/zulip/zulip.git
57 lines
1.7 KiB
Python
Executable File
57 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import pylibmc
|
|
import traceback
|
|
import logging
|
|
from humbug_tools import DEPLOYMENTS_DIR, LOCK_DIR, TIMESTAMP_FORMAT, FAIL, ENDC
|
|
import datetime
|
|
import shutil
|
|
|
|
logging.basicConfig(format="%(asctime)s update-deployment: %(message)s",
|
|
level=logging.INFO)
|
|
|
|
if len(sys.argv) > 1:
|
|
oldrev = sys.argv[1]
|
|
newrev = sys.argv[2]
|
|
refname = sys.argv[3]
|
|
|
|
subprocess.check_call(["mkdir", '-p',
|
|
DEPLOYMENTS_DIR,
|
|
'/home/humbug/logs'])
|
|
|
|
try:
|
|
os.mkdir(LOCK_DIR)
|
|
except OSError:
|
|
print FAIL + "Deployment already in progress. Please run\n" \
|
|
+ " update-deployment %s %s %s\n" % (oldrev, newrev, refname) \
|
|
+ "manually when the current deployment finishes." + ENDC
|
|
sys.exit(1)
|
|
|
|
timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT)
|
|
deploy_path = os.path.join(DEPLOYMENTS_DIR, timestamp)
|
|
|
|
logging.info("Cloning the repository")
|
|
subprocess.check_call(["git", "clone", "-q", "-b", refname,
|
|
"humbug@git.humbughq.com:/srv/git/humbug.git",
|
|
deploy_path], stdout=open('/dev/null', 'w'))
|
|
os.chdir(deploy_path)
|
|
|
|
# Delete all .pyc files to avoid old module files hanging around
|
|
subprocess.check_call(["find", ".", "-name", "*.pyc", "-delete"], stdout=open('/dev/null', 'w'))
|
|
|
|
# Update static files
|
|
logging.info("Updating static files")
|
|
subprocess.check_call(["./tools/update-prod-static"])
|
|
|
|
subprocess.check_call(["ln", '-nsf', deploy_path, os.path.join(DEPLOYMENTS_DIR, "current")])
|
|
|
|
logging.info("Restarting server...")
|
|
subprocess.check_call(["./tools/restart-server"])
|
|
|
|
logging.info("Deployment complete")
|
|
shutil.rmtree(LOCK_DIR)
|
|
|
|
subprocess.check_call(["./tools/purge-deployments"])
|