diff --git a/scripts/unpack-zulip b/scripts/unpack-zulip new file mode 100755 index 0000000000..4215d9bd21 --- /dev/null +++ b/scripts/unpack-zulip @@ -0,0 +1,26 @@ +#!/usr/bin/python -u +import os +import sys +import subprocess +import datetime +import tempfile + +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +from zulip_tools import DEPLOYMENTS_DIR, TIMESTAMP_FORMAT, FAIL, ENDC + +if len(sys.argv) != 2: + print FAIL + "Usage: %s " % (sys.argv[0],) + ENDC + sys.exit(1) + +tarball_path = sys.argv[1] + +timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT) +deploy_path = os.path.join(DEPLOYMENTS_DIR, timestamp) + +extract_path = tempfile.mkdtemp() +subprocess.check_call(["tar", "-xf", tarball_path, "-C", extract_path]) +subprocess.check_call(["mv", os.path.join(extract_path, "zulip-server"), deploy_path]) +subprocess.check_call(["rmdir", extract_path]) + +print deploy_path +sys.exit(0) diff --git a/scripts/upgrade-zulip b/scripts/upgrade-zulip index 0a77112b89..834cd81a26 100755 --- a/scripts/upgrade-zulip +++ b/scripts/upgrade-zulip @@ -6,7 +6,6 @@ import logging import datetime import shutil import time -import tempfile sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, TIMESTAMP_FORMAT, FAIL, WARNING, ENDC @@ -20,8 +19,6 @@ if len(sys.argv) != 2: tarball_path = sys.argv[1] -subprocess.check_call(["mkdir", '-p', DEPLOYMENTS_DIR, '/home/zulip/logs']) - start_time = time.time() got_lock = False while time.time() - start_time < 300: @@ -46,14 +43,12 @@ timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT) deploy_path = os.path.join(DEPLOYMENTS_DIR, timestamp) logging.info("Unpacking the tarball") -extract_path = tempfile.mkdtemp() -subprocess.check_call(["tar", "-xf", tarball_path, "-C", extract_path]) -subprocess.check_call(["mv", os.path.join(extract_path, "zulip-server"), deploy_path]) -subprocess.check_call(["rmdir", extract_path]) -os.chdir(deploy_path) +deploy_path = subprocess.check_output([os.path.join(os.path.dirname(__file__), 'unpack-zulip'), + tarball_path]) +os.chdir(deploy_path.strip()) logging.info("Restarting server...") -subprocess.check_call(["./scripts/restart-server"]) +subprocess.check_output(["./scripts/restart-server"]) logging.info("Deployment complete") shutil.rmtree(LOCK_DIR)