enterprise: Make upgrade-zulip do puppet applies and schema migrations

(imported from commit 6d0109e6cd6a02ed5d57b0c0b4c9dc052f158344)
This commit is contained in:
Zev Benjamin 2013-11-13 15:04:07 -05:00
parent 67ed16a12e
commit 0b592a27b1
2 changed files with 32 additions and 5 deletions

View File

@ -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)

View File

@ -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 <tarball>" % (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)