Permalink
Browse files

Updating fabric file to fulfil the entire deployment of a new box wit…

…h no hiccups. Still needs a hosts file, and maybe some envvars for hostname.
  • Loading branch information...
1 parent b2a7db3 commit 9769b61b7fc947651a12c504447caf0f02d19e2e @samuelclay committed Mar 15, 2011
Showing with 101 additions and 24 deletions.
  1. +7 −0 config/motd
  2. +43 −0 config/pystartup.py
  3. +1 −1 config/zshrc
  4. +49 −22 fabfile.py
  5. +1 −1 local_settings.py.template
View
@@ -0,0 +1,7 @@
+ _ _ ____ _
+ | \ | | | _ \| |
+ | \| | _____ _____| |_) | |_ _ _ __
+ | . ` |/ _ \ \ /\ / / __| _ <| | | | | '__|
+ | |\ | __/\ V V /\__ \ |_) | | |_| | |
+ |_| \_|\___| \_/\_/ |___/____/|_|\__,_|_|
+
View
@@ -0,0 +1,43 @@
+# Add auto-completion and a stored history file of commands to your Python
+# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
+# bound to the Esc key by default (you can change it - see readline docs).
+#
+# Store the file in ~/.pystartup, and set an environment variable to point
+# to it, e.g. "export PYTHONSTARTUP=/max/home/itamar/.pystartup" in bash.
+#
+# Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the
+# full path to your home directory.
+
+import atexit
+import os
+import readline
+import rlcompleter
+
+historyPath = os.path.expanduser("~/.pyhistory")
+historyTmp = os.path.expanduser("~/.pyhisttmp.py")
+
+endMarkerStr= "# # # histDUMP # # #"
+
+saveMacro= "import readline; readline.write_history_file('"+historyTmp+"'); \
+ print '####>>>>>>>>>>'; print ''.join(filter(lambda lineP: \
+ not lineP.strip().endswith('"+endMarkerStr+"'), \
+ open('"+historyTmp+"').readlines())[:])+'####<<<<<<<<<<'"+endMarkerStr
+
+readline.parse_and_bind('tab: complete')
+readline.parse_and_bind('\C-w: "'+saveMacro+'"')
+
+def save_history(historyPath=historyPath, endMarkerStr=endMarkerStr):
+ import readline
+ readline.write_history_file(historyPath)
+ # Now filter out those line containing the saveMacro
+ lines= filter(lambda lineP, endMarkerStr=endMarkerStr:
+ not lineP.strip().endswith(endMarkerStr), open(historyPath).readlines())
+ open(historyPath, 'w+').write(''.join(lines))
+
+if os.path.exists(historyPath):
+ readline.read_history_file(historyPath)
+
+atexit.register(save_history)
+
+del os, atexit, readline, rlcompleter, save_history, historyPath
+del historyTmp, endMarkerStr, saveMacro
View
@@ -11,7 +11,7 @@ export LC_COLLATE='C'
source $ZSH/oh-my-zsh.sh
export PROMPT='%{$fg_bold[green]%}%n@%M:%{$fg_bold[blue]%}%~ $(git_prompt_info)%{$reset_color%}%(!.#.$) '
-export PYTHONSTARTUP=/root/.pystartup
+export PYTHONSTARTUP=$HOME/.pystartup
export LSCOLORS='gxgxcxdxBxegedabagacad'
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
View
@@ -97,55 +97,64 @@ def backup_postgresql():
# = Bootstrap =
# =============
-def setup_common():
- setup_installs()
- setup_user()
- setup_server()
- setup_repo()
- setup_libxml()
- setup_python()
- setup_mongoengine()
- setup_supervisor()
-
def setup_app():
setup_common()
setup_gunicorn()
update_gunicorn()
setup_nginx()
def setup_db():
+ setup_common()
+ setup_db_installs()
+ setup_rabbitmq()
setup_postgres()
setup_mongo()
def setup_task():
+ setup_common()
+ setup_task_installs()
setup_celery()
+def setup_common():
+ setup_installs()
+ setup_user()
+ setup_repo()
+ setup_local_files()
+ setup_libxml()
+ setup_python()
+ setup_mongoengine()
+ setup_supervisor()
+
# ==================
# = Setup - Common =
# ==================
def setup_installs():
sudo('apt-get -y update')
sudo('apt-get -y upgrade')
- sudo('apt-get -y install build-essential gcc scons sysstat iotop git zsh python-dev locate python-software-properties libpcre3-dev libssl-dev make pgbouncer python-psycopg2 libmemcache0 memcached python-memcache libyaml-0-2 python-yaml python-numpy python-scipy python-imaging munin munin-node munin-plugins-extra curl')
+ sudo('apt-get -y install build-essential gcc scons libreadline-dev sysstat iotop git zsh python-dev locate python-software-properties libpcre3-dev libssl-dev make pgbouncer python-psycopg2 libmemcache0 memcached python-memcache libyaml-0-2 python-yaml python-numpy python-scipy python-imaging munin munin-node munin-plugins-extra curl')
sudo('add-apt-repository ppa:pitti/postgresql')
sudo('apt-get -y update')
sudo('apt-get -y install postgresql-client-9.0')
sudo('mkdir -p /var/run/postgresql')
sudo('chown postgres.postgres /var/run/postgresql')
+ put('config/pgbouncer.conf', '/etc/pgbouncer/pgbouncer.ini', use_sudo=True)
+ put('config/munin.conf', '/etc/munin/munin.conf', use_sudo=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 sclay -s /bin/zsh')
+ put('config/motd', '/etc/motd.tail', use_sudo=True)
+
def setup_user():
# run('useradd -c "NewsBlur" -m conesus -s /bin/zsh')
# run('openssl rand -base64 8 | tee -a ~conesus/.password | passwd -stdin conesus')
run('mkdir -p ~/.ssh && chmod 700 ~/.ssh')
+ run('rm -fr ~/.ssh/id_dsa*')
run('ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ""')
- put("~/.ssh/id_dsa.pub", "~/.ssh/authorized_keys")
-
-def setup_server():
- sudo('hostname app02')
+ run('touch ~/.ssh/authorized_keys')
+ put("~/.ssh/id_dsa.pub", "authorized_keys")
+ run('mv authorized_keys ~/.ssh/')
def setup_repo():
run('mkdir -p ~/code')
@@ -154,6 +163,10 @@ def setup_repo():
run('cp local_settings.py.template local_settings.py')
run('mkdir -p logs')
+def setup_local_files():
+ put("config/toprc", "./.toprc")
+ put("config/zshrc", "./.zshrc")
+
def setup_libxml():
sudo('apt-get -y install libxml2-dev libxslt1-dev python-lxml')
# with cd('~/code'):
@@ -168,12 +181,13 @@ def setup_libxml():
def setup_python():
sudo('easy_install pip')
- sudo('easy_install fabric django django-celery django-compress South django-devserver django-extensions guppy psycopg2 pymongo BeautifulSoup pyyaml nltk lxml oauth2 pytz boto')
- sudo('su -c \'echo "import sys; sys.setdefaultencoding(\"utf-8\")" > /usr/lib/python2.6/sitecustomize.py\'')
+ sudo('easy_install fabric django celery django-celery django-compress South django-devserver django-extensions guppy psycopg2 pymongo BeautifulSoup pyyaml nltk lxml oauth2 pytz boto')
+ sudo('su -c \'echo "import sys; sys.setdefaultencoding(\\\\"utf-8\\\\")" > /usr/lib/python2.6/sitecustomize.py\'')
+ put('config/pystartup.py', '.pystartup')
def setup_mongoengine():
with cd('~/code'):
- run('git clone -f https://github.com/hmarr/mongoengine.git')
+ run('git clone https://github.com/hmarr/mongoengine.git')
sudo('ln -s ~/code/mongoengine/mongoengine /usr/local/lib/python2.6/dist-packages/mongoengine')
def setup_supervisor():
@@ -184,17 +198,19 @@ def setup_supervisor():
# ===============
def setup_app_installs():
- sudo('apt-get install -y mongodb-clients')
+ # sudo('apt-get install -y ')
+ pass
def setup_gunicorn():
with cd('~/code'):
run('git clone -f git://github.com/benoitc/gunicorn.git')
sudo('ln -s ~/code/gunicorn/gunicorn /usr/local/lib/python2.6/dist-packages/gunicorn')
+ put('config/supervisor_gunicorn.conf', '/etc/supervisord/conf.d/gunicorn.conf', use_sudo=True)
def update_gunicorn():
with cd('~/code/gunicorn'):
run('git pull')
- sudo('python setup.py install')
+ sudo('python setup.py develop')
def setup_nginx():
with cd('~/code'):
@@ -218,18 +234,29 @@ def setup_nginx():
# = Setup - DB =
# ==============
+def setup_db_installs():
+ pass
+
+def setup_rabbitmq():
+ sudo('apt-get install -y rabbitmq-server')
+
def setup_postgres():
sudo('apt-get -y install postgresql-9.0 postgresql-client-9.0 postgresql-contrib-9.0 libpq-dev')
def setup_mongo():
- sudo('sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10')
+ sudo('apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10')
sudo('echo "deb http://downloads.mongodb.org/distros/ubuntu 10.10 10gen" >> /etc/apt/sources.list.d/10gen.list')
+ sudo('apt-get update')
sudo('apt-get -y install mongodb')
# ================
# = Setup - Task =
# ================
+def setup_task_installs():
+ # sudo('apt-get install -y ')
+ pass
+
def setup_celery():
pass
@@ -33,7 +33,7 @@ BROKER_HOST = "127.0.0.1"
# Logging (setup for development)
LOG_TO_STREAM = True
if len(logging._handlerList) < 1:
- LOG_FILE = '/home/conesus/newsblur/logs/development.log'
+ LOG_FILE = '~/newsblur/logs/development.log'
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)-12s: %(message)s',
datefmt='%b %d %H:%M:%S',

0 comments on commit 9769b61

Please sign in to comment.