From 0b592a27b18715033b8f03857e5c6f69c7a595b7 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Wed, 13 Nov 2013 15:04:07 -0500 Subject: [PATCH] enterprise: Make upgrade-zulip do puppet applies and schema migrations (imported from commit 6d0109e6cd6a02ed5d57b0c0b4c9dc052f158344) --- scripts/unpack-zulip | 3 +-- scripts/upgrade-zulip | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/scripts/unpack-zulip b/scripts/unpack-zulip index a19c1b32ac..ec99677310 100755 --- a/scripts/unpack-zulip +++ b/scripts/unpack-zulip @@ -22,8 +22,7 @@ subprocess.check_call(["mv", os.path.join(extract_path, "zulip-server"), deploy_ subprocess.check_call(["rmdir", extract_path]) subprocess.check_call(["ln", "-nsf", "/etc/zulip/settings.py", os.path.join(deploy_path, "zproject/local_settings.py")]) -subprocess.check_call(["cp", "-rT", os.path.join(deploy_path, 'prod-static/serve'), - '/home/zulip/prod-static']) +subprocess.check_call(["ln", '-nsf', deploy_path, os.path.join(DEPLOYMENTS_DIR, "next")]) print deploy_path sys.exit(0) diff --git a/scripts/upgrade-zulip b/scripts/upgrade-zulip index af7615bfde..0887cdd9ab 100755 --- a/scripts/upgrade-zulip +++ b/scripts/upgrade-zulip @@ -6,6 +6,7 @@ import logging import datetime import shutil import time +import pwd sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, FAIL, WARNING, ENDC @@ -13,6 +14,10 @@ from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, FAIL, WARNING, ENDC 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: print FAIL + "Usage: %s " % (sys.argv[0],) + ENDC sys.exit(1) @@ -39,13 +44,36 @@ if not got_lock: + ENDC sys.exit(1) +def su_to_zulip(): + pwent = pwd.getpwnam("zulip") + os.setgid(pwent.pw_gid) + os.setuid(pwent.pw_uid) + logging.info("Unpacking the tarball") deploy_path = subprocess.check_output([os.path.join(os.path.dirname(__file__), 'unpack-zulip'), - tarball_path]) -os.chdir(deploy_path.strip()) + tarball_path], preexec_fn=su_to_zulip) +deploy_path = deploy_path.strip() +os.chdir(deploy_path) + +logging.info("Upgrading system packages...") +subprocess.check_call(["apt-get", "update"]) +subprocess.check_call(["apt-get", "upgrade"]) + +logging.info("Stopping Zulip...") +subprocess.check_call(["supervisorctl", "stop", "zulip-workers:*", "zulip-django", + "zulip-tornado"], preexec_fn=su_to_zulip) + +logging.info("Applying puppet changes...") +subprocess.check_call(["./scripts/zulip-puppet-apply", "--force"]) +subprocess.check_call(["apt-get", "upgrade"]) + +logging.info("Applying database migrations...") +subprocess.check_call(["./manage.py", "migrate"], preexec_fn=su_to_zulip) logging.info("Restarting server...") -subprocess.check_output(["./scripts/restart-server"]) +subprocess.check_call(["cp", "-rT", os.path.join(deploy_path, 'prod-static/serve'), + '/home/zulip/prod-static'], preexec_fn=su_to_zulip) +subprocess.check_output(["./scripts/restart-server"], preexec_fn=su_to_zulip) logging.info("Deployment complete") shutil.rmtree(LOCK_DIR)