py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2022-01-05 23:10:28 +01:00
|
|
|
import argparse
|
2020-06-11 00:54:34 +02:00
|
|
|
import configparser
|
|
|
|
import logging
|
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 subprocess
|
2020-06-11 00:54:34 +02:00
|
|
|
import sys
|
2018-08-12 01:56:58 +02:00
|
|
|
import time
|
2013-11-14 06:32:49 +01:00
|
|
|
|
2016-11-28 23:29:01 +01:00
|
|
|
TARBALL_ARCHIVE_PATH = "/home/zulip/archives"
|
2015-11-16 17:40:32 +01:00
|
|
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), "..", ".."))
|
2020-06-11 00:54:34 +02:00
|
|
|
from scripts.lib.zulip_tools import (
|
|
|
|
DEPLOYMENTS_DIR,
|
|
|
|
assert_running_as_root,
|
|
|
|
get_config_file,
|
|
|
|
get_deploy_options,
|
|
|
|
get_deployment_lock,
|
|
|
|
release_deployment_lock,
|
|
|
|
su_to_zulip,
|
|
|
|
)
|
2018-12-15 21:24:18 +01:00
|
|
|
|
2020-04-22 01:09:50 +02:00
|
|
|
config_file: configparser.RawConfigParser = get_config_file()
|
2018-12-17 19:44:24 +01:00
|
|
|
deploy_options = get_deploy_options(config_file)
|
2018-11-15 11:07:43 +01:00
|
|
|
|
2018-11-19 19:50:25 +01:00
|
|
|
assert_running_as_root(strip_lib_from_paths=True)
|
2013-11-14 06:32:49 +01:00
|
|
|
|
2020-06-08 21:37:16 +02:00
|
|
|
# make sure we have appropriate file permissions
|
|
|
|
os.umask(0o22)
|
|
|
|
|
2018-08-12 01:56:58 +02:00
|
|
|
logging.Formatter.converter = time.gmtime
|
2021-02-12 08:19:30 +01:00
|
|
|
logging.basicConfig(format="%(asctime)s upgrade-zulip: %(message)s", level=logging.INFO)
|
2013-11-14 06:32:49 +01:00
|
|
|
|
2022-01-05 23:10:28 +01:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("tarball", help="Path to Zulip Server tarball")
|
|
|
|
args, extra_options = parser.parse_known_args()
|
2013-11-14 06:32:49 +01:00
|
|
|
|
2022-01-05 23:10:28 +01:00
|
|
|
error_rerun_script = f"{DEPLOYMENTS_DIR}/current/scripts/upgrade-zulip {args.tarball}"
|
2016-01-10 20:58:11 +01:00
|
|
|
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.
|
2020-05-26 10:39:08 +02:00
|
|
|
logging.info("Archiving the tarball under %s", TARBALL_ARCHIVE_PATH)
|
2017-10-25 20:06:11 +02:00
|
|
|
os.makedirs(TARBALL_ARCHIVE_PATH, exist_ok=True)
|
2022-01-05 23:10:28 +01:00
|
|
|
archived_tarball_path = os.path.join(TARBALL_ARCHIVE_PATH, os.path.basename(args.tarball))
|
|
|
|
shutil.copy(args.tarball, archived_tarball_path)
|
2016-01-10 20:36:38 +01:00
|
|
|
subprocess.check_output(["chown", "-R", "zulip:zulip", TARBALL_ARCHIVE_PATH])
|
|
|
|
|
2016-01-10 19:46:09 +01:00
|
|
|
logging.info("Unpacking the tarball")
|
2021-02-12 08:20:45 +01:00
|
|
|
unpack_zulip = os.path.realpath(os.path.join(os.path.dirname(__file__), "unpack-zulip"))
|
2021-02-12 08:19:30 +01:00
|
|
|
deploy_path = subprocess.check_output(
|
2022-01-22 07:52:54 +01:00
|
|
|
[unpack_zulip, archived_tarball_path], preexec_fn=su_to_zulip, text=True
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
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)
|
2021-04-21 03:26:33 +02:00
|
|
|
try:
|
|
|
|
subprocess.check_call(
|
2022-01-05 23:10:28 +01:00
|
|
|
[
|
|
|
|
os.path.abspath("./scripts/lib/upgrade-zulip-stage-2"),
|
|
|
|
deploy_path,
|
|
|
|
*deploy_options,
|
|
|
|
*extra_options,
|
|
|
|
]
|
2021-04-21 03:26:33 +02:00
|
|
|
)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
# There's no use in showing a stacktrace here; it just hides
|
|
|
|
# the error from stage 2.
|
|
|
|
sys.exit(1)
|
2016-01-10 19:46:09 +01:00
|
|
|
finally:
|
2016-01-10 20:58:11 +01:00
|
|
|
release_deployment_lock()
|