mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
The #! line processing interpreted the argument to pass to `env` as "python2.7 -u", which obviously isn't a real program. We fix this by setting the PYTHONUNBUFFERED environment variable inside the program, which has the same effect. Thanks to Dan Fedele for the bug report and suggested solution!
68 lines
2.1 KiB
Python
Executable File
68 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python2.7
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
import logging
|
|
import datetime
|
|
import shutil
|
|
import time
|
|
|
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
|
from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, FAIL, WARNING, ENDC, make_deploy_path
|
|
|
|
logging.basicConfig(format="%(asctime)s update-deployment: %(message)s",
|
|
level=logging.INFO)
|
|
|
|
if len(sys.argv) != 2:
|
|
print FAIL + "Usage: update-deployment refname" + ENDC
|
|
sys.exit(1)
|
|
|
|
refname = sys.argv[1]
|
|
|
|
subprocess.check_call(["mkdir", '-p',
|
|
DEPLOYMENTS_DIR,
|
|
'/home/zulip/logs'])
|
|
|
|
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/tools/update-deployment %s\n" % (DEPLOYMENTS_DIR, refname) \
|
|
+ "manually when the current deployment finishes." + ENDC
|
|
sys.exit(1)
|
|
|
|
deploy_path = make_deploy_path()
|
|
|
|
logging.info("Cloning the repository")
|
|
subprocess.check_call(["git", "clone", "-q", "-b", refname,
|
|
"git@git.zulip.net:eng/zulip.git",
|
|
deploy_path], stdout=open('/dev/null', 'w'))
|
|
os.chdir(deploy_path)
|
|
# Hack to deploy images not included in open source project
|
|
subprocess.check_call(["cp", "-a", "/etc/zulip/zulip-dropbox.png",
|
|
os.path.join(deploy_path, "static/images/logo")])
|
|
|
|
# Update static files
|
|
logging.info("Updating static files")
|
|
subprocess.check_call(["./tools/update-prod-static", "--prev-deploy",
|
|
os.path.join(DEPLOYMENTS_DIR, 'current')])
|
|
|
|
logging.info("Restarting server...")
|
|
subprocess.check_call(["./scripts/restart-server"])
|
|
|
|
logging.info("Deployment complete")
|
|
shutil.rmtree(LOCK_DIR)
|
|
|
|
subprocess.check_call(["./scripts/purge-old-deployments"])
|