From 787215d7439d600f88fbcd4a35812bac4e0a0df0 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Thu, 31 Oct 2013 19:00:30 -0400 Subject: [PATCH] [manual] Switch over to new /etc/zulip/zulip.conf config file Run the following commands as root before deploying this branch: # /root/zulip/tools/migrate-server-config # rm /etc/zulip/machinetype /etc/zulip/server /etc/zulip/local /etc/humbug-machinetype /etc/humbug-server /etc/humbug-local (imported from commit aa7dcc50d2f4792ce33834f14761e76512fca252) --- puppet/zulip-internal/manifests/base.pp | 8 -------- puppet/zulip-internal/manifests/init.pp | 14 +------------- puppet/zulip/manifests/local_server.pp | 8 -------- scripts/restart-server | 8 +++----- scripts/setup/install | 4 +++- scripts/zulip-puppet-apply | 16 +++++++++++++--- tools/install-server | 4 +++- tools/migrate-server-config | 25 +++++++++++++++++++++++++ zproject/local_settings.py | 13 ++++++++----- zproject/settings.py | 13 ++++++++----- 10 files changed, 64 insertions(+), 49 deletions(-) create mode 100755 tools/migrate-server-config diff --git a/puppet/zulip-internal/manifests/base.pp b/puppet/zulip-internal/manifests/base.pp index 9109188d82..3b07310a9b 100644 --- a/puppet/zulip-internal/manifests/base.pp +++ b/puppet/zulip-internal/manifests/base.pp @@ -28,14 +28,6 @@ class zulip-internal::base { source => 'puppet:///modules/zulip-internal/root_authorized_keys', } - # This is just an empty file. It's used by the app to test if it's running - # in production. - file { '/etc/zulip/server': - ensure => file, - mode => 644, - content => '', - } - file { '/usr/local/sbin/zulip-ec2-configure-interfaces': ensure => file, mode => 755, diff --git a/puppet/zulip-internal/manifests/init.pp b/puppet/zulip-internal/manifests/init.pp index efe130e4c2..556f97ad1f 100644 --- a/puppet/zulip-internal/manifests/init.pp +++ b/puppet/zulip-internal/manifests/init.pp @@ -1,14 +1,2 @@ -class zulip-internal ($machinetype) { - class { "zulip-internal::$machinetype": } - - file { '/etc/zulip/machinetype': - ensure => file, - mode => 644, - content => "$machinetype\n", - } - - Exec { path => "/usr/sbin:/usr/bin:/sbin:/bin" } - - class {'apt': } - +class zulip-internal { } diff --git a/puppet/zulip/manifests/local_server.pp b/puppet/zulip/manifests/local_server.pp index 4ecabb5921..5e728e2d2b 100644 --- a/puppet/zulip/manifests/local_server.pp +++ b/puppet/zulip/manifests/local_server.pp @@ -38,14 +38,6 @@ class zulip::local_server { target => '/home/zulip/deployments/current/prod-static/serve', } - # This is just an empty file. It's used by the app to test if it's running - # on a local server. - file { '/etc/zulip/local': - ensure => file, - mode => 644, - content => '', - } - file { "/usr/share/postgresql/9.1/tsearch_data/zulip_english.stop": require => Package["postgresql-9.1"], ensure => file, diff --git a/scripts/restart-server b/scripts/restart-server index 70851d572a..578d19c046 100755 --- a/scripts/restart-server +++ b/scripts/restart-server @@ -15,11 +15,9 @@ logging.basicConfig(format="%(asctime)s restart-server: %(message)s", deploy_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..')) os.chdir(deploy_path) -if os.path.exists("/etc/zulip/server"): - with open("/etc/zulip/machinetype") as mtf: - if pwd.getpwuid(os.getuid())[0] != "zulip": - logging.error("Must be run as user 'zulip'.") - sys.exit(1) +if pwd.getpwuid(os.getuid())[0] != "zulip": + logging.error("Must be run as user 'zulip'.") + sys.exit(1) # Send a statsd event on restarting the server subprocess.check_call(["python", "./manage.py", "send_stats", "incr", "events.server_restart", str(int(time.time()))]) diff --git a/scripts/setup/install b/scripts/setup/install index bb0cfb892b..5097dfbde5 100644 --- a/scripts/setup/install +++ b/scripts/setup/install @@ -10,7 +10,9 @@ cp -a /root/zulip/puppet/zulip/files/puppet.conf /etc/puppet/ ssh $SSH_OPTS "$server" -t -i "$amazon_key_file" -lroot < "local_server"}' +mkdir /etc/zulip +echo -e "[machine]\npuppet_classes = zulip::local_server" > /etc/zulip/zulip.conf +/root/zulip/scripts/zulip-puppet-apply -f cp -a /root/zulip /home/zulip/zulip chown -R zulip:zulip /home/zulip/zulip diff --git a/scripts/zulip-puppet-apply b/scripts/zulip-puppet-apply index 3913c28568..9a83d283c6 100755 --- a/scripts/zulip-puppet-apply +++ b/scripts/zulip-puppet-apply @@ -2,6 +2,8 @@ import sys import subprocess +import ConfigParser +import re force = False extra_args = sys.argv[1:] @@ -10,10 +12,18 @@ if len(extra_args) and extra_args[0] in ('-f', '--force'): force = True eatra_args = extra_args[1:] -with open('/etc/zulip/machinetype') as f: - machinetype = f.readline().strip() +config = ConfigParser.RawConfigParser() +config.read("/etc/zulip/zulip.conf") -puppet_cmd = ["puppet", "apply", "-e", "class {'zulip-internal': machinetype => '%s'}" % (machinetype,)] +puppet_config = """ +Exec { path => "/usr/sbin:/usr/bin:/sbin:/bin" } +class { 'apt': } +""" + +for pclass in re.split(r'\s*,\s*', config.get('machine', 'puppet_classes')): + puppet_config += "class { '%s': }\n" % (pclass,) + +puppet_cmd = ["puppet", "apply", "-e", puppet_config] puppet_cmd += extra_args if force: diff --git a/tools/install-server b/tools/install-server index 535f669a3c..712eb0d7e2 100755 --- a/tools/install-server +++ b/tools/install-server @@ -83,7 +83,9 @@ cp -a /root/zulip/puppet/zulip/files/puppet.conf /etc/puppet/ userdel admin passwd -d root -puppet apply -e 'class {"zulip": machinetype => "$type"}' +mkdir /etc/zulip +echo -e "[machine]\npuppet_classes =" $type > /etc/zulip/zulip.conf +/root/zulip/scripts/zulip-puppet-apply -f cp -a /root/zulip /home/zulip/zulip chown -R zulip:zulip /home/zulip/zulip # These server restarting bits should be moveable into puppet-land, ideally diff --git a/tools/migrate-server-config b/tools/migrate-server-config new file mode 100755 index 0000000000..adc752d4a5 --- /dev/null +++ b/tools/migrate-server-config @@ -0,0 +1,25 @@ +#!/usr/bin/python +import os +import ConfigParser +import platform +import re + +config = ConfigParser.RawConfigParser() +config.add_section("machine") + +with open('/etc/zulip/machinetype') as f: + machinetype = f.readline().strip() + +config.set('machine', 'puppet_classes', "zulip-internal::%s" % (machinetype,)) + +if os.path.exists('/etc/zulip/server'): + if platform.node() == 'staging.zulip.net': + deploy_type = 'staging' + elif not not re.match(r'^test', platform.node()): + deploy_type = 'test' + else: + deploy_type = 'prod' + + config.set('machine', 'deploy_type', deploy_type) + +config.write(open('/etc/zulip/zulip.conf', 'w')) diff --git a/zproject/local_settings.py b/zproject/local_settings.py index fdc42c6e76..fc3eff271e 100644 --- a/zproject/local_settings.py +++ b/zproject/local_settings.py @@ -1,7 +1,7 @@ # Secret Django settings for the Zulip project import os import platform -import re +import ConfigParser # Make this unique, and don't share it with anybody. SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' @@ -44,14 +44,17 @@ EMAIL_HOST_USER = 'zulip@zulip.com' EMAIL_HOST_PASSWORD = 'xxxxxxxxxxxxxxxx' EMAIL_PORT = 587 +config_file = ConfigParser.RawConfigParser() +config_file.read("/etc/zulip/zulip.conf") + # Whether we're running in a production environment. Note that DEPLOYED does # **not** mean hosted by us; customer sites are DEPLOYED and LOCAL_SERVER # and as such should not for example assume they are the main Zulip site. -DEPLOYED = os.path.exists('/etc/zulip/server') -STAGING_DEPLOYED = (platform.node() == 'staging.zulip.net') -TESTING_DEPLOYED = not not re.match(r'^test', platform.node()) +DEPLOYED = config_file.has_option('machine', 'deploy_type') +STAGING_DEPLOYED = DEPLOYED and config_file.get('machine', 'deploy_type') == 'staging' +TESTING_DEPLOYED = DEPLOYED and config_file.get('machine', 'deploy_type') == 'test' -LOCAL_SERVER = os.path.exists('/etc/zulip-local') +LOCAL_SERVER = DEPLOYED and config_file.get('machine', 'deploy_type') == 'local' if TESTING_DEPLOYED: EXTERNAL_HOST = platform.node() diff --git a/zproject/settings.py b/zproject/settings.py index b1e7caa4a5..f38e98cf03 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -5,19 +5,22 @@ import os import platform import time -import re import sys +import ConfigParser from zerver.openid import openid_failure_handler +config_file = ConfigParser.RawConfigParser() +config_file.read("/etc/zulip/zulip.conf") + # Whether we're running in a production environment. Note that DEPLOYED does # **not** mean hosted by us; customer sites are DEPLOYED and LOCAL_SERVER # and as such should not for example assume they are the main Zulip site. -DEPLOYED = os.path.exists('/etc/zulip/server') -STAGING_DEPLOYED = (platform.node() == 'staging.zulip.net') -TESTING_DEPLOYED = not not re.match(r'^test', platform.node()) +DEPLOYED = config_file.has_option('machine', 'deploy_type') +STAGING_DEPLOYED = DEPLOYED and config_file.get('machine', 'deploy_type') == 'staging' +TESTING_DEPLOYED = DEPLOYED and config_file.get('machine', 'deploy_type') == 'test' -LOCAL_SERVER = os.path.exists('/etc/zulip-local') +LOCAL_SERVER = DEPLOYED and config_file.get('machine', 'deploy_type') == 'local' # TODO: Clean this up if TESTING_DEPLOYED: