mirror of https://github.com/zulip/zulip.git
74 lines
2.7 KiB
Python
Executable File
74 lines
2.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import os
|
|
from six.moves import configparser
|
|
import sys
|
|
import subprocess
|
|
import logging
|
|
|
|
config_file = configparser.RawConfigParser()
|
|
config_file.read("/etc/zulip/zulip.conf")
|
|
LOCAL_GIT_CACHE_DIR = '/srv/zulip.git'
|
|
|
|
try:
|
|
git_url = config_file.get('deployment', 'git_repo_url')
|
|
except (configparser.NoSectionError, configparser.NoOptionError):
|
|
git_url = "https://github.com/zulip/zulip.git"
|
|
try:
|
|
deploy_options = config_file.get('deployment', 'deploy_options').strip().split()
|
|
except (configparser.NoSectionError, configparser.NoOptionError):
|
|
deploy_options = []
|
|
|
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
|
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, make_deploy_path, \
|
|
get_deployment_lock, release_deployment_lock, su_to_zulip
|
|
|
|
logging.basicConfig(format="%(asctime)s upgrade-zulip-from-git: %(message)s",
|
|
level=logging.INFO)
|
|
|
|
if os.getuid() != 0:
|
|
logging.error("Must be run as root.")
|
|
sys.exit(1)
|
|
|
|
if len(sys.argv) != 2:
|
|
print(FAIL + "Usage: upgrade-zulip-from-git refname" + ENDC)
|
|
sys.exit(1)
|
|
|
|
refname = sys.argv[1]
|
|
|
|
subprocess.check_call(["mkdir", '-p',
|
|
DEPLOYMENTS_DIR,
|
|
'/home/zulip/logs'])
|
|
|
|
error_rerun_script = "%s/current/scripts/upgrade-zulip-from-git %s" % (DEPLOYMENTS_DIR, refname)
|
|
get_deployment_lock(error_rerun_script)
|
|
|
|
try:
|
|
deploy_path = make_deploy_path()
|
|
if not os.path.exists(LOCAL_GIT_CACHE_DIR):
|
|
logging.info("Cloning the repository")
|
|
subprocess.check_call(["git", "clone", "-q", git_url, "--mirror", LOCAL_GIT_CACHE_DIR],
|
|
stdout=open('/dev/null', 'w'))
|
|
subprocess.check_call(["chown", "-R", "zulip:zulip", LOCAL_GIT_CACHE_DIR])
|
|
|
|
logging.info("Fetching the latest commits")
|
|
os.chdir(LOCAL_GIT_CACHE_DIR)
|
|
subprocess.check_call(["git", "remote", "set-url", "origin", git_url], preexec_fn=su_to_zulip)
|
|
subprocess.check_call(["git", "fetch", "-q"], preexec_fn=su_to_zulip)
|
|
|
|
subprocess.check_call(["git", "clone", "-q", "-b", refname, LOCAL_GIT_CACHE_DIR, deploy_path],
|
|
stdout=open('/dev/null', 'w'),
|
|
preexec_fn=su_to_zulip)
|
|
os.chdir(deploy_path)
|
|
|
|
subprocess.check_call(["ln", "-nsf", "/etc/zulip/settings.py",
|
|
os.path.join(deploy_path, "zproject/prod_settings.py")])
|
|
|
|
subprocess.check_call(["ln", '-nsf', deploy_path, os.path.join(DEPLOYMENTS_DIR, "next")])
|
|
|
|
subprocess.check_call([os.path.join(deploy_path, "scripts", "lib", "upgrade-zulip-stage-2"),
|
|
deploy_path, "--from-git"] + deploy_options)
|
|
finally:
|
|
release_deployment_lock()
|