Split out unpack-zulip from the upgrade script.

(imported from commit e41a8ad01c3042c7d877fb3aa17f9617dc2b0121)
This commit is contained in:
Tim Abbott 2013-11-08 16:41:12 -05:00
parent 5b71ceb03c
commit 5c450afd2d
2 changed files with 30 additions and 9 deletions

26
scripts/unpack-zulip Executable file
View File

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

View File

@ -6,7 +6,6 @@ import logging
import datetime import datetime
import shutil import shutil
import time import time
import tempfile
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, TIMESTAMP_FORMAT, FAIL, WARNING, ENDC 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] tarball_path = sys.argv[1]
subprocess.check_call(["mkdir", '-p', DEPLOYMENTS_DIR, '/home/zulip/logs'])
start_time = time.time() start_time = time.time()
got_lock = False got_lock = False
while time.time() - start_time < 300: 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) deploy_path = os.path.join(DEPLOYMENTS_DIR, timestamp)
logging.info("Unpacking the tarball") logging.info("Unpacking the tarball")
extract_path = tempfile.mkdtemp() deploy_path = subprocess.check_output([os.path.join(os.path.dirname(__file__), 'unpack-zulip'),
subprocess.check_call(["tar", "-xf", tarball_path, "-C", extract_path]) tarball_path])
subprocess.check_call(["mv", os.path.join(extract_path, "zulip-server"), deploy_path]) os.chdir(deploy_path.strip())
subprocess.check_call(["rmdir", extract_path])
os.chdir(deploy_path)
logging.info("Restarting server...") logging.info("Restarting server...")
subprocess.check_call(["./scripts/restart-server"]) subprocess.check_output(["./scripts/restart-server"])
logging.info("Deployment complete") logging.info("Deployment complete")
shutil.rmtree(LOCK_DIR) shutil.rmtree(LOCK_DIR)