<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>underlost labs</title>
 <link href="http://underlost.github.com/feed/atom.xml" rel="self"/>
 <link href="http://underlost.github.com/"/>
 <updated>2012-03-27T13:11:18-07:00</updated>
 <id>http://underlost.github.com/</id>
 <author>
   <name>Tyler Rilling</name>
   <email>tyler@underlost.net</email>
 </author>

 
 <entry>
   <title>PostgreSQL 8.4 On a Media Temple (dv) Server</title>
   <link href="http://underlost.github.com/2012/03/27/2012-postgres-on-mt-server.html"/>
   <updated>2012-03-27T00:00:00-07:00</updated>
   <id>http://tom.preston-werner.com/2012/03/27/2012-postgres-on-mt-server</id>
   <content type="html">&lt;h2&gt;Preface&lt;/h2&gt;
&lt;p&gt;Last week Django 1.4 was officially released. With it brought a lot of new features, so I wanted to upgrade most of my projects as soon as I could. I use Heroku for almost all of my Django apps, and have a (dv) server from Media Temple for serving static content and database hosting. Up until Django&amp;#8217;s new release, this worked really well. I soon discovered a problem though. A minimum of PostgreSQL 8.2 is now required. My server only had 8.1.&lt;/p&gt;
&lt;h2&gt;The Problem&lt;/h2&gt;
&lt;p&gt;Now, there are all kinds of tutorials and guides walking you through an install or upgrade of PostgreSQL 8.x to other versions, including 9. What these guides fail to take into account is servers with the Plesk webadmin interface also running. According to Plesk&amp;#8217;s release notes (which itself is hard to find), they only support &amp;#8220;8.4&amp;#8221;. Now, that is good enough for me.&lt;/p&gt;
&lt;p&gt;One of the few nice things about Plesk is it comes with a handy updater/installer that will actually occasionally work. It can be accessed by running: &lt;pre class=&quot;terminal&quot;&gt;/usr/local/psa/admin/sbin/autoinstaller&lt;/pre&gt; as root, or anything equivalent. After fixing a few errors, I successfully updated to the latest version of Plesk (10.4.4). While Plesk claims the auto-installer &lt;strong&gt;should&lt;/strong&gt; install PostgreSQL to 8.4, they are wrong when it comes to CentOS 5. Instead, it installs the 8.1 branch.&lt;/p&gt;
&lt;h2&gt;The Solution&lt;/h2&gt;
&lt;p&gt;If you attempt to install via Yum, you will presented with two separate package: &amp;#8220;postgresql&amp;#8221; (8.1) and &amp;#8220;postgresql84&amp;#8221; (8.4.x). Either will install just fine. The server will start, and you can even start using it. While both technically work, only the 8.1 package will be recognized by Plesk. So, how do we solve this? We&amp;#8217;ll need to manually grab the latest 8.4 &lt;span class=&quot;caps&quot;&gt;RPM&lt;/span&gt; package from PostgreSQL servers.&lt;/p&gt;
&lt;p&gt;First, we&amp;#8217;ll need to remove any existing packages:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;yum remove postgresql&lt;/pre&gt;
&lt;p&gt;And hide the current packages in the yum repo, by editing &lt;strong&gt;/etc/yum.repos.d/CentOS-Base.repo&lt;/strong&gt; and adding this line to the &lt;strong&gt;[base]&lt;/strong&gt; and &lt;strong&gt;[updates]&lt;/strong&gt; sections:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;exclude=postgresql*&lt;/pre&gt;
&lt;p&gt;This will tell yum t ignore packages from the normal repos, and only display the packages from the &lt;span class=&quot;caps&quot;&gt;RPM&lt;/span&gt; we&amp;#8217;ll be using. So next we&amp;#8217;ll get PostgreSQL 8.4 directly from the PostgreSQL servers:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;wget http://yum.postgresql.org/8.4/redhat/rhel-5-x86_64/pgdg-centos-8.4-3.noarch.rpm&lt;/pre&gt;
&lt;p&gt;And install the rpm distribution:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;rpm -ivh pgdg-centos-8.4-3.noarch.rpm&lt;/pre&gt;
&lt;p&gt;From there we can install PostgreSQL like usual:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;
yum list postgres*
yum install postgresql-server
...
service postgresql initdb
chkconfig postgresql on
service postgresql start
&lt;/pre&gt;
&lt;p&gt;Next we begin the process of letting Plesk access it, by adding our Plesk admin account (make sure to use the same username/password as the plesk account):&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;
su postgres
createuser -slPE
&lt;/pre&gt;
&lt;p&gt;We done as the postgres user, so you can exit out of it:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;exit&lt;/pre&gt;
&lt;p&gt;Enable access for you to allow logins from the (dv) server. Edit &lt;strong&gt;/var/lib/pgsql/data/pg_hba.conf&lt;/strong&gt; and comment out the line:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;all all 127.0.0.1/32 ident&lt;/pre&gt;

&lt;p&gt;And add this line:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;all all 127.0.0.1/32 md5&lt;/pre&gt;
&lt;p&gt;Finally, we can register PostgreSQL 8.4 with Plesk:&lt;/p&gt;
&lt;pre class=&quot;terminal&quot;&gt;/usr/local/psa/bin/database-server --update-server localhost:5432 -type postgresql -admin admin -passwd `cat /etc/psa/.psa.shadow` &amp;amp;&amp;amp; service psa restart&lt;/pre&gt;
&lt;p&gt;If all went well, PostgreSQL 8.4 will finally be installed and accesible through Plesk/pgAdmin!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Running Jekyll on Heroku</title>
   <link href="http://underlost.github.com/2012/01/23/jekyll-heroku.html"/>
   <updated>2012-01-23T00:00:00-08:00</updated>
   <id>http://tom.preston-werner.com/2012/01/23/jekyll-heroku</id>
   <content type="html"></content>
 </entry>
 
 <entry>
   <title>Django on Heroku</title>
   <link href="http://underlost.github.com/2011/04/05/django-heroku.html"/>
   <updated>2011-04-05T00:00:00-07:00</updated>
   <id>http://tom.preston-werner.com/2011/04/05/django-heroku</id>
   <content type="html">&lt;p&gt;&lt;em&gt;Last updated Jan. 23 2012.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;With Heroku&amp;#8217;s new cedar stack, getting a production ready Django app up and running is pretty painless. I&amp;#8217;ll assume you already have git and the heroku gem installed. If you dont you can follow the guides here and here. In this example we&amp;#8217;ll be using Celery for job queues and Gunicorn for our webserver. Start by creating your project. I&amp;#8217;ll be using my own website, located in a directory called underlost.net:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Tyler$ django-admin.py startproject underlost&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Next, using your favorite etxt editor, create two files, &lt;code&gt;Procfile&lt;/code&gt; and &lt;code&gt;requirements.txt&lt;/code&gt;. &lt;code&gt;Requirements.txt&lt;/code&gt; is used for Pip, and more or less tells Heroku what Python Packages you will need. We&amp;#8217;re creating a basic Django website, so we wont need too many packages.&lt;/p&gt;
&lt;script src='https://gist.github.com/1664936.js?file=requirements.txt'&gt;&lt;/script&gt;&lt;p&gt;Next we&amp;#8217;ll need to make some edits to &lt;code&gt;settings.py&lt;/code&gt;. Include Celery near the top like so:&lt;/p&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;
import djcelery
djcelery.setup_loader()

BROKER_HOST = &quot;localhost&quot;
BROKER_PORT = 5672
BROKER_USER = &quot;guest&quot;
BROKER_PASSWORD = &quot;guest&quot;
BROKER_VHOST = &quot;/&quot;
&lt;/pre&gt;
&lt;p&gt;Add &lt;code&gt;'djcelery'&lt;/code&gt;, and &lt;code&gt;'gunicorn'&lt;/code&gt; to your apps list.&lt;/p&gt;
&lt;p&gt;Now we need to tell Heroku to use gunicorn and Celery. This is managed by creating our &lt;code&gt;Procfile&lt;/code&gt; outside the project folder:&lt;/p&gt;
&lt;script src='https://gist.github.com/1664930.js?file=Procfile'&gt;&lt;/script&gt;&lt;p&gt;&lt;em&gt;web:&lt;/em&gt; Specifies the command to serve our app over Gunicorn instead of the built in server included with django, while &lt;em&gt;Worker:&lt;/em&gt; specified what to use for our job queue. Neither is really required if you&amp;#8217;re just testing things, but if you&amp;#8217;re planning on creating something that can handle more than a few users at a time, its advised.&lt;/p&gt;
&lt;p&gt;Once we have that taken care of, We can create our git repo:&lt;/p&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;
$ git init
$ git add .
$ git commit -m init
&lt;/pre&gt;
&lt;p&gt;Now we need to create our app on heroku, assuming you already have an account. Django only runs on the new Cedar stack, so we need to specify it:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;heroku create --stack cedar&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Lastly, you need to push everything to Heroku:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;git push heroku master&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Open your new site in a browser, &lt;code&gt;heroku open&lt;/code&gt;. Everything should be running fast on Gunicorn. You&amp;#8217;re ready to start writing your new django Application!&lt;/p&gt;</content>
 </entry>
 
 
</feed>
