enterprise: Log the output of upgrade-zulip and install scripts

We may eventually want to rotate the log files, but this seems good
enough for now.

(imported from commit 9a54fa6b40bc62f68e52ef552c1a676856b21829)
This commit is contained in:
Zev Benjamin 2013-11-14 00:32:49 -05:00 committed by Tim Abbott
parent 7940f7725c
commit 87a6838e0e
4 changed files with 121 additions and 116 deletions

61
scripts/lib/install Executable file
View File

@ -0,0 +1,61 @@
#!/bin/bash -xe
# Assumes we've already been untarred
# First, install any updates from the apt repo that may be needed
wget -O /root/enterprise.asc https://apt.zulip.com/enterprise.asc
apt-key add /root/enterprise.asc
cat >/etc/apt/sources.list.d/zulip.list <<EOF
deb http://apt.zulip.com/enterprise precise v1
EOF
apt-get update
apt-get -y dist-upgrade
apt-get install -y puppet git
cp -a /root/zulip/puppet/zulip/files/puppet.conf /etc/puppet/
mkdir -p /etc/zulip
echo -e "[machine]\npuppet_classes = zulip::enterprise\ndeploy_type = enterprise" > /etc/zulip/zulip.conf
/root/zulip/scripts/zulip-puppet-apply -f
# These server restarting bits should be moveable into puppet-land, ideally
apt-get -y upgrade
if [ -e "/etc/init.d/nginx" ]; then
service nginx restart
fi
if [ -e "/etc/init.d/apache2" ]; then
service apache2 restart
fi
/root/zulip/scripts/setup/generate_enterprise_secrets.py
mv /root/zulip/zproject/local_settings_generated.py /etc/zulip/settings.py
ln -nsf /etc/zulip/settings.py /root/zulip/zproject/local_settings.py
/root/zulip/scripts/setup/configure-rabbitmq
/root/zulip/scripts/setup/postgres-init-db
deploy_path=$(/root/zulip/zulip_tools.py make_deploy_path)
mv /root/zulip "$deploy_path"
ln -nsf /home/zulip/deployments/next /root/zulip
ln -nsf "$deploy_path" /home/zulip/deployments/next
ln -nsf "$deploy_path" /home/zulip/deployments/current
ln -nsf /etc/zulip/settings.py "$deploy_path"/zproject/local_settings.py
cp -rT "$deploy_path"/prod-static/serve /home/zulip/prod-static
chown -R zulip:zulip /home/zulip /var/log/zulip /etc/zulip/settings.py
chown zulip:zulip /var/run/supervisor.sock
cd /home/zulip/deployments/current
set +x
cat <<EOF
Installation complete!
Now edit /etc/zulip/settings.py and fill in the mandatory values.
Once you've done that, please run:
su zulip -c /home/zulip/deployments/current/scripts/setup/initialize-database
EOF

56
scripts/lib/upgrade-zulip Executable file
View File

@ -0,0 +1,56 @@
#!/usr/bin/python -u
import os
import sys
import subprocess
import logging
import shutil
import time
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, FAIL, WARNING, ENDC, \
su_to_zulip
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)
tarball_path = sys.argv[1]
start_time = time.time()
got_lock = False
while time.time() - start_time < 300:
try:
os.mkdir(LOCK_DIR)
got_lock = True
break
except OSError:
print WARNING + "Another deployment in progress; waiting for lock..." + ENDC
time.sleep(10)
if not got_lock:
print FAIL + "Deployment already in progress. Please run\n" \
+ " %s/current/scripts/upgrade-zulip %s\n" % (DEPLOYMENTS_DIR, tarball_path) \
+ "manually when the previous deployment finishes, or run\n" \
+ " rmdir %s\n" % (LOCK_DIR,) \
+ "if the previous deployment crashed." \
+ ENDC
sys.exit(1)
logging.info("Unpacking the tarball")
deploy_path = subprocess.check_output([os.path.join(os.path.dirname(__file__),
'..', 'unpack-zulip'),
tarball_path], preexec_fn=su_to_zulip)
deploy_path = deploy_path.strip()
os.chdir(deploy_path)
subprocess.check_call(["./scripts/upgrade-zulip-stage-2", deploy_path])
logging.info("Deployment complete")
shutil.rmtree(LOCK_DIR)

63
scripts/setup/install Executable file → Normal file
View File

@ -1,61 +1,2 @@
#!/bin/bash -xe
# Assumes we've already been untarred
# First, install any updates from the apt repo that may be needed
wget -O /root/enterprise.asc https://apt.zulip.com/enterprise.asc
apt-key add /root/enterprise.asc
cat >/etc/apt/sources.list.d/zulip.list <<EOF
deb http://apt.zulip.com/enterprise precise v1
EOF
apt-get update
apt-get -y dist-upgrade
apt-get install -y puppet git
cp -a /root/zulip/puppet/zulip/files/puppet.conf /etc/puppet/
mkdir -p /etc/zulip
echo -e "[machine]\npuppet_classes = zulip::enterprise\ndeploy_type = enterprise" > /etc/zulip/zulip.conf
/root/zulip/scripts/zulip-puppet-apply -f
# These server restarting bits should be moveable into puppet-land, ideally
apt-get -y upgrade
if [ -e "/etc/init.d/nginx" ]; then
service nginx restart
fi
if [ -e "/etc/init.d/apache2" ]; then
service apache2 restart
fi
/root/zulip/scripts/setup/generate_enterprise_secrets.py
mv /root/zulip/zproject/local_settings_generated.py /etc/zulip/settings.py
ln -nsf /etc/zulip/settings.py /root/zulip/zproject/local_settings.py
/root/zulip/scripts/setup/configure-rabbitmq
/root/zulip/scripts/setup/postgres-init-db
deploy_path=$(/root/zulip/zulip_tools.py make_deploy_path)
mv /root/zulip "$deploy_path"
ln -nsf /home/zulip/deployments/next /root/zulip
ln -nsf "$deploy_path" /home/zulip/deployments/next
ln -nsf "$deploy_path" /home/zulip/deployments/current
ln -nsf /etc/zulip/settings.py "$deploy_path"/zproject/local_settings.py
cp -rT "$deploy_path"/prod-static/serve /home/zulip/prod-static
chown -R zulip:zulip /home/zulip /var/log/zulip /etc/zulip/settings.py
chown zulip:zulip /var/run/supervisor.sock
cd /home/zulip/deployments/current
set +x
cat <<EOF
Installation complete!
Now edit /etc/zulip/settings.py and fill in the mandatory values.
Once you've done that, please run:
su zulip -c /home/zulip/deployments/current/scripts/setup/initialize-database
EOF
#!/bin/bash
$(dirname $(dirname $0))/lib/install "$@" 2>&1 | tee -a /var/log/zulip/install.log

View File

@ -1,55 +1,2 @@
#!/usr/bin/python -u
import os
import sys
import subprocess
import logging
import shutil
import time
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from zulip_tools import DEPLOYMENTS_DIR, LOCK_DIR, FAIL, WARNING, ENDC, \
su_to_zulip
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)
tarball_path = sys.argv[1]
start_time = time.time()
got_lock = False
while time.time() - start_time < 300:
try:
os.mkdir(LOCK_DIR)
got_lock = True
break
except OSError:
print WARNING + "Another deployment in progress; waiting for lock..." + ENDC
time.sleep(10)
if not got_lock:
print FAIL + "Deployment already in progress. Please run\n" \
+ " %s/current/scripts/upgrade-zulip %s\n" % (DEPLOYMENTS_DIR, tarball_path) \
+ "manually when the previous deployment finishes, or run\n" \
+ " rmdir %s\n" % (LOCK_DIR,) \
+ "if the previous deployment crashed." \
+ ENDC
sys.exit(1)
logging.info("Unpacking the tarball")
deploy_path = subprocess.check_output([os.path.join(os.path.dirname(__file__), 'unpack-zulip'),
tarball_path], preexec_fn=su_to_zulip)
deploy_path = deploy_path.strip()
os.chdir(deploy_path)
subprocess.check_call(["./scripts/upgrade-zulip-stage-2", deploy_path])
logging.info("Deployment complete")
shutil.rmtree(LOCK_DIR)
#!/bin/bash
$(dirname $0)/lib/upgrade-zulip "$@" 2>&1 | tee -a /var/log/zulip/upgrade.log