Merge branch 'master' into circular

* master:
  cleanup and fixing some of my stupid bugs
  cleanup and fixing some of my stupid bugs
  whoops, that section isn't called in the normal installation process. Reverted.
  Fix to make detecting if the install is a dev env work properly
  Fixed typo. Also, extracted most of the instances of a specific username out to `env.user`, so you don't need to search&replace to do an install. Lastly, added a separate function to change the shell of the host, so it's easier to disable.

Conflicts:
	fabfile.py
This commit is contained in:
Samuel Clay 2013-05-09 16:54:29 -07:00
commit 716d78525a
2 changed files with 125 additions and 116 deletions

45
fabfile.py vendored
View file

@ -33,11 +33,13 @@ env.NEWSBLUR_PATH = "~/projects/newsblur"
env.SECRETS_PATH = "~/projects/secrets-newsblur"
env.VENDOR_PATH = "~/projects/code"
env.EC2_KEY_NAME = "sclay"
# =========
# = Roles =
# =========
env.user = 'sclay'
env.user = 'sclay' # Why is this being set? It should be correctly set by fabric.
try:
hosts_path = os.path.expanduser(os.path.join(env.SECRETS_PATH, 'configs/hosts.yml'))
roles = yaml.load(open(hosts_path))
@ -293,6 +295,7 @@ def setup_time_calibration():
def setup_common():
setup_installs()
change_shell()
setup_user()
setup_sudoers()
setup_ulimit()
@ -378,21 +381,25 @@ def setup_task(queue=None, skip_common=False):
def setup_installs():
sudo('apt-get -y update')
sudo('apt-get -y upgrade')
sudo('apt-get -y install build-essential gcc scons libreadline-dev sysstat iotop git zsh python-dev locate python-software-properties software-properties-common libpcre3-dev libncurses5-dev libdbd-pg-perl libssl-dev make pgbouncer python-psycopg2 libyaml-0-2 python-yaml python-numpy python-scipy python-imaging curl monit ufw')
sudo('apt-get -y install build-essential gcc scons libreadline-dev sysstat iotop git python-dev locate python-software-properties software-properties-common libpcre3-dev libncurses5-dev libdbd-pg-perl libssl-dev make pgbouncer python-psycopg2 libyaml-0-2 python-yaml python-numpy python-scipy python-imaging curl monit ufw')
# sudo('add-apt-repository ppa:pitti/postgresql')
sudo('apt-get -y update')
sudo('apt-get -y install postgresql-client')
sudo('mkdir -p /var/run/postgresql')
sudo('chown postgres.postgres /var/run/postgresql')
with settings(warn_only=True):
run('git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh')
run('curl -O http://peak.telecommunity.com/dist/ez_setup.py')
sudo('python ez_setup.py -U setuptools && rm ez_setup.py')
sudo('chsh %s -s /bin/zsh' % env.user)
with settings(warn_only=True):
sudo('mkdir -p %s' % env.VENDOR_PATH)
sudo('chown %s.%s %s' % (env.user, env.user, env.VENDOR_PATH))
def change_shell():
sudo('apt-get -y install zsh')
with settings(warn_only=True):
run('git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh')
sudo('chsh %s -s /bin/zsh' % env.user)
def setup_user():
# run('useradd -c "NewsBlur" -m newsblur -s /bin/zsh')
# run('openssl rand -base64 8 | tee -a ~conesus/.password | passwd -stdin conesus')
@ -532,7 +539,7 @@ def setup_pymongo_repo():
# sudo('python setup.py install')
sudo('rm -fr /usr/local/lib/python2.7/dist-packages/pymongo*')
sudo('rm -fr /usr/local/lib/python2.7/dist-packages/bson*')
sudo('rm -fr /usr/local/lib/python2.7/dist-packages/gridgs*')
sudo('rm -fr /usr/local/lib/python2.7/dist-packages/gridfs*')
sudo('ln -fs %s /usr/local/lib/python2.7/dist-packages/' %
os.path.join(env.VENDOR_PATH, 'pymongo/{pymongo,bson,gridfs}'))
@ -944,7 +951,7 @@ def setup_db_mdadm():
def setup_original_page_server():
setup_node()
sudo('mkdir -p /srv/originals')
sudo('chown sclay.sclay -R /srv/originals')
sudo('chown %s.%s -R /srv/originals' % (env.user, env.user)) # We assume that the group is the same name as the user. It's common on linux
put('config/supervisor_node_original.conf',
'/etc/supervisor/conf.d/node_original.conf', use_sudo=True)
sudo('supervisorctl reread')
@ -1043,18 +1050,19 @@ def setup_do(name, size=2):
def add_user_to_do():
env.user = "root"
repo_user = "sclay"
with settings(warn_only=True):
run('useradd -m sclay')
setup_sudoers("sclay")
run('mkdir -p ~sclay/.ssh && chmod 700 ~sclay/.ssh')
run('rm -fr ~sclay/.ssh/id_dsa*')
run('ssh-keygen -t dsa -f ~sclay/.ssh/id_dsa -N ""')
run('touch ~sclay/.ssh/authorized_keys')
run('useradd -m %s' % (repo_user))
setup_sudoers("%s" % (repo_user))
run('mkdir -p ~%s/.ssh && chmod 700 ~%s/.ssh' % (repo_user, repo_user))
run('rm -fr ~%s/.ssh/id_dsa*' % (repo_user))
run('ssh-keygen -t dsa -f ~%s/.ssh/id_dsa -N ""' % (repo_user, repo_user))
run('touch ~%s/.ssh/authorized_keys' % (repo_user, repo_user))
put("~/.ssh/id_dsa.pub", "authorized_keys")
run('echo `cat authorized_keys` >> ~sclay/.ssh/authorized_keys')
run('echo `cat authorized_keys` >> ~%s/.ssh/authorized_keys' % (repo_user))
run('rm authorized_keys')
run('chown sclay.sclay -R ~sclay/.ssh')
env.user = "sclay"
run('chown %s.%s -R ~%s/.ssh' % (repo_user, repo_user, repo_user))
env.user = repo_user
# ===============
# = Setup - EC2 =
@ -1066,7 +1074,7 @@ def setup_ec2():
INSTANCE_TYPE = 'c1.medium'
conn = EC2Connection(django_settings.AWS_ACCESS_KEY_ID, django_settings.AWS_SECRET_ACCESS_KEY)
reservation = conn.run_instances(AMI_NAME, instance_type=INSTANCE_TYPE,
key_name='sclay',
key_name=env.EC2_KEY_NAME,
security_groups=['db-mongo'])
instance = reservation.instances[0]
print "Booting reservation: %s/%s (size: %s)" % (reservation, instance, INSTANCE_TYPE)
@ -1098,7 +1106,8 @@ def setup_ec2():
def restore_postgres(port=5433):
backup_date = '2013-01-29-09-00'
yes = prompt("Dropping and creating NewsBlur PGSQL db. Sure?")
if yes != 'y': return
if yes != 'y':
return
# run('PYTHONPATH=%s python utils/backups/s3.py get backup_postgresql_%s.sql.gz' % (env.NEWSBLUR_PATH, backup_date))
# sudo('su postgres -c "createuser -p %s -U newsblur"' % (port,))
run('dropdb newsblur -p %s -U postgres' % (port,), pty=False)

View file

@ -80,7 +80,7 @@ ALLOWED_HOSTS = ['*']
PRODUCTION = NEWSBLUR_DIR.find('/home/conesus/newsblur') == 0
STAGING = NEWSBLUR_DIR.find('/home/conesus/staging') == 0
DEVELOPMENT = NEWSBLUR_DIR.find('/Users/') == 0
DEVELOPMENT = (NEWSBLUR_DIR.find('/Users/') == 0)
# ===========================
# = Django-specific Modules =