2016-04-07 15:03:22 +02:00
|
|
|
#!/usr/bin/env python
|
2016-03-10 17:15:34 +01:00
|
|
|
from __future__ import print_function
|
2013-11-14 06:32:49 +01:00
|
|
|
import os
|
2016-01-10 20:36:38 +01:00
|
|
|
import shutil
|
2013-11-14 06:32:49 +01:00
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import logging
|
|
|
|
|
2016-01-10 20:36:38 +01:00
|
|
|
TARBALL_ARCHIVE_PATH="/home/zulip/archives"
|
2015-11-16 17:40:32 +01:00
|
|
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
|
|
|
|
2013-11-14 06:32:49 +01:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
2016-08-13 17:46:19 +02:00
|
|
|
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, \
|
2016-01-10 20:58:11 +01:00
|
|
|
mkdir_p, su_to_zulip, get_deployment_lock, release_deployment_lock
|
2013-11-14 06:32:49 +01:00
|
|
|
|
|
|
|
logging.basicConfig(format="%(asctime)s upgrade-zulip: %(message)s",
|
|
|
|
level=logging.INFO)
|
|
|
|
|
|
|
|
if os.getuid() != 0:
|
|
|
|
logging.error("Must be run as root.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if len(sys.argv) != 2:
|
2016-03-10 17:15:34 +01:00
|
|
|
print(FAIL + "Usage: %s <tarball>" % (sys.argv[0],) + ENDC)
|
2013-11-14 06:32:49 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
tarball_path = sys.argv[1]
|
|
|
|
|
2016-01-10 20:58:11 +01:00
|
|
|
error_rerun_script = "%s/current/scripts/upgrade-zulip %s" % (DEPLOYMENTS_DIR, tarball_path)
|
|
|
|
get_deployment_lock(error_rerun_script)
|
2013-11-14 06:32:49 +01:00
|
|
|
|
2016-01-10 19:46:09 +01:00
|
|
|
try:
|
2016-01-10 20:36:38 +01:00
|
|
|
# Copy the release tarball to an archival path that's readable by
|
|
|
|
# the Zulip user, and then unpack it from that directory, so that
|
|
|
|
# we can unpack using the Zulip user even if the original path was
|
|
|
|
# not readable by the Zulip user.
|
|
|
|
logging.info("Archiving the tarball under %s" % (TARBALL_ARCHIVE_PATH,))
|
|
|
|
mkdir_p(TARBALL_ARCHIVE_PATH)
|
|
|
|
archived_tarball_path = os.path.join(TARBALL_ARCHIVE_PATH, os.path.basename(tarball_path))
|
|
|
|
shutil.copy(tarball_path, archived_tarball_path)
|
|
|
|
subprocess.check_output(["chown", "-R", "zulip:zulip", TARBALL_ARCHIVE_PATH])
|
|
|
|
|
2016-01-10 19:46:09 +01:00
|
|
|
logging.info("Unpacking the tarball")
|
|
|
|
unpack_zulip = os.path.realpath(os.path.join(os.path.dirname(__file__), 'unpack-zulip'))
|
2016-01-10 20:36:38 +01:00
|
|
|
deploy_path = subprocess.check_output([unpack_zulip, archived_tarball_path],
|
2016-07-26 06:40:05 +02:00
|
|
|
preexec_fn=su_to_zulip, universal_newlines=True)
|
2013-11-14 06:32:49 +01:00
|
|
|
|
2016-01-10 20:12:33 +01:00
|
|
|
# Chdir to deploy_path and then run upgrade-zulip-stage-2 from the
|
|
|
|
# new version of Zulip (having the upgrade logic run from the new
|
|
|
|
# version is much better for fixing bugs in the upgrade process).
|
2016-01-10 19:46:09 +01:00
|
|
|
deploy_path = deploy_path.strip()
|
|
|
|
os.chdir(deploy_path)
|
2016-01-10 20:14:09 +01:00
|
|
|
subprocess.check_call([os.path.abspath("./scripts/lib/upgrade-zulip-stage-2"), deploy_path])
|
2016-01-10 19:46:09 +01:00
|
|
|
finally:
|
2016-01-10 20:58:11 +01:00
|
|
|
release_deployment_lock()
|