Great, as far as I am concerned more is better, organization will come
with time. I "skipped" my Ubuntu deploy script and focused Webfaction
so your script is helpful for me as well. I went a little over the top
and although I am happy with the results it took a lot longer than I
was expecting and started to get bogged down in the formalities rather
than the functionalities ; )

You are right, we should start a collection. We could list URLs in one
place, perhaps Slicehost or we could ask Massimo for a section in the
online book, this would allow multiple people to contribute recipes
and or links to fabfiles etc.

Massimo, what do you think?

Thanks,

Chris

On 2 mar, 13:45, pbreit <pbreitenb...@gmail.com> wrote:
> Looks like a good start. Here's what I use. Not as well organized. It sets
> up a fresh Ubunutu 10.04 and installs Cherokee, UWSGI, Postgres, Web2py,
> Postfix and my project from Bitbucket. I also have "deploy" for pushing out
> changes. There doesn't seem to be any collection of Fabric recipes anywhere
> which is unfortunate.
>
> Any feedback is appreciated.
>
> from fabric.api import *
>
> # globals
> pw = 'password'
> db = 'main'
> web2pyversion = 'R-1.92.1'
> domain = 'domain.com'
> app = 'init'
> app_path = '/var/web2py/applications/init'
>
> # environments
> def prod():
> env.hosts = ['0.0.0.0']
> env.user = 'root'
>
> def test():
> env.hosts = ['0.0.0.0']
> env.user = 'root'
>
> # tasks
> def setup():
> setup_ubuntu()
> setup_pgsql()
> setup_postfix()
> setup_uwsgi()
> setup_cherokee()
> setup_web2py()
> setup_project()
>
> def deploy():
> sudo('cd %s; hg pull' % (app_path), user='www-data')
> run('cd %s; hg update' % (app_path))
> sudo('chown -R www-data:www-data %s' % (app_path))
> restart_cherokee()
>
> # utilities
> def setup_ubuntu():
> sudo('/usr/sbin/locale-gen en_US.UTF-8; /usr/sbin/update-locale
> LANG=en_US.UTF-8')
> sudo('ln -sf /usr/share/zoneinfo/US/Pacific /etc/localtime')
> sudo('apt-get update')
> sudo('apt-get -y upgrade -y')
> sudo('apt-get -y install -y zip unzip tar wget build-essential python-dev
> python-software-properties libxml2-dev mercurial')
> sudo('rm /etc/hosts')
> sudo("""echo '127.0.0.1 localhost.localdomain localhost
> 174.143.140.9 web1.domain.com web1
> ' >> /etc/hosts""" )
>
> def setup_uwsgi():
> sudo('cd /var; wgethttp://projects.unbit.it/downloads/uwsgi-latest.tar.gz')
> sudo('cd /var; tar xvf uwsgi-latest.tar.gz')
> sudo('cd /var; mv uwsgi-0* uwsgi')
> sudo('cd /var/uwsgi; python uwsgiconfig.py --build')
> sudo('cd /var/uwsgi; cp uwsgi /usr/local/bin/')
>
> def setup_pgsql():
> sudo('apt-get -y install postgresql python-psycopg2 postgresql-contrib')
> sudo('psql -c "ALTER USER postgres WITH ENCRYPTED PASSWORD \'%s\';"' % (pw),
> user='postgres')
> sudo('psql -c "CREATE DATABASE %s WITH OWNER postgres"' % (db),
> user='postgres')
> sudo('/etc/init.d/postgresql-8.4 restart')
>
> def new_db():
> sudo('psql -c "DROP DATABASE %s"' % (db), user='postgres')
> sudo('psql -c "CREATE DATABASE %s WITH OWNER postgres"' % (db),
> user='postgres')
> sudo('/etc/init.d/postgresql-8.4 restart')
>
> def setup_web2py():
> #sudo('cd /var; wgethttp://web2py.com/examples/static/web2py_src.zip')
> #sudo('cd /var; unzip web2py_src.zip')
> sudo('rm -R /var/web2py')
> sudo('cd /var; hg clonehttps://web2py.googlecode.com/hg/web2py')
> sudo('chown -R www-data:www-data /var/web2py')
> sudo('cd /var/web2py; hg update %s' % (web2pyversion), user='www-data')
> sudo("""echo '<uwsgi>
> <pythonpath>/var/web2py/</pythonpath>
> <module>wsgihandler</module>
> <socket>/tmp/uwsgi.sock</socket>
> <master/>
> <processes>4</processes>
> <memory-report/>
> </uwsgi>
> ' >> /var/web2py/cherokee-config.xml""")
>
> def setup_cherokee():
> sudo('add-apt-repository ppa:cherokee-webserver')
> sudo('apt-get update')
> sudo('apt-get install -y cherokee rrdtool libcherokee-mod-rrd
> libcherokee-mod-libssl')
> sudo('rm -rf /etc/cherokee')
> sudo('mkdir /etc/cherokee')
> put('cherokee.conf', '/etc/cherokee/cherokee.conf')
> sudo('mkdir /etc/cherokee/ssl')
> sudo('cd /etc/cherokee/ssl; dd if=/dev/random of=rand.dat bs=1024 count=1')
> sudo('cd /etc/cherokee/ssl; openssl genrsa -out cakey.key -rand rand.dat
> 2048')
> sudo('cd /etc/cherokee/ssl; openssl req -batch -new -key cakey.key -out
> cakey.csr')
> sudo('cd /etc/cherokee/ssl; openssl x509 -req -days 1780 -set_serial 1 -in
> cakey.csr -signkey cakey.key -out cakey.pem')
> sudo('cd /etc/cherokee/ssl; cat cakey.key cakey.pem > server.pem')
> sudo('cd /etc/cherokee/ssl; rm -f rand.dat')
> sudo('chown -R www-data:www-data /etc/cherokee')
> sudo('/etc/init.d/cherokee restart')
>
> def restart_cherokee():
> sudo('/etc/init.d/cherokee restart')
>
> def setup_postfix():
> sudo('DEBIAN_FRONTEND=noninteractive apt-get install -y postfix')
> #postconf -e 'myhostname = web1.domain.com'
> #postconf -e 'mydestination = web1.domain.com, domain.com,
> localhost.localdomain, localhost'
> #postconf -e 'smtpd_recipient_restrictions =
> permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
> #postconf -e 'inet_interfaces = all'
> sudo('/etc/init.d/postfix restart')
>
> def setup_project():
> sudo('rm -rf %s' % (app_path))
> sudo('cd /var/web2py/applications; hg clone
> https://pbreit:%...@bitbucket.org/pbreit/%s' % (pw, app))
> sudo('rm %s/models/1_settings.py' % (app_path))
> sudo('mv %s/private/1_settings_prod.py %s/models/1_settings_prod.py' %
> (app_path, app_path))
> sudo('chown -R www-data:www-data %s' % (app_path))
> sudo('mv %s/private/routes.py /var/web2py/routes.py' % (app_path))
> sudo('cd /var/web2py; python -c "from gluon.main import save_password;
> save_password(\'%s\',80)"' % (pw))

Reply via email to