Sunday, August 5, 2012

Disabling OSX's PostgreSQL to use Heroku's Postgres.app

If you want to use Postgres.app, you'll probably want to turn off any existing PostgreSQL servers you have run to free up port 5432. Typically these are configured to run via launchd, so you'll need to use launchctl to disable them, e.g.:

sudo launchctl remove /Library/LaunchDaemons/com.edb.launchd.postgresql-9.0.plist


As you can see you need to pass the path to a .plist file. There's a couple of places these can exist, so you can use grep to find them:

grep -ri postgres /Library/LaunchDaemons /System/Library/LaunchDaemons ~/Library/LaunchAgents

Sunday, July 15, 2012

Installing Solr 3.6.0 on Ubuntu from source


1. Make a solr user

    useradd -d /opt/solr solr

2. Download a tarball of Solr 3.6.0 and install to /opt/solr

    wget http://archive.apache.org/dist/lucene/solr/3.6.0/apache-solr-3.6.0.tgz
    tar -zxf apache-solr-3.6.0.tgz
    mv apache-solr-3.6.0 /opt/solr
    chown -R solr /opt/solr

4. Make log directory

    mkdir /var/log/solr
    chown solr /var/log/solr

5. Create Upstart job at /etc/init/solr.conf:

    description "Solr"


    start on runlevel [2345]
    stop on runlevel [016]
    respawn


    exec su solr -l -c "cd /opt/solr/example && java -Dsolr.solr.home=/etc/solr -Djetty.port=8080 -Djetty.host=0.0.0.0 -Djetty.logs=/var/log/solr -jar start.jar > /var/log/solr/stdouterr.log 2>&1"

6. Create the base data directory for cores:

    mkdir /var/lib/solr
    chown solr /var/lib/solr

7. Make /etc/solr/solr.xml:

    <?xml version="1.0" encoding="UTF-8" ?>
    <solr persistent="false">
      <cores adminPath="/admin/cores">
        <core name="example.com" instanceDir="/etc/solr/example.com">
          <property name="dataDir" value="/var/lib/solr/example.com/data" />
        </core>
      </cores>
    </solr>

8. Make core conf in /etc/solr/example.com/conf/{schema.xml,solrconfig.xml}

Thursday, June 21, 2012

Disable Apache on OSX Server

I seem to have lost the OSX Server configuration app, which made trying to turn off Apache a little tricky. The solution is to use launchctl:

sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist

See man launchctl for details.

Sunday, May 6, 2012

Turn Python warnings into errors

It's generally good practice to run unit tests with warnings turned into errors to ensure deprecation warnings are honoured in a timely manner. Despite often coming across people saying that this can be done with a command line flag, after a bit of searching around I couldn't find a simple example of how to do this.

After a bit of trial and error it turns out to be very simple:

python -W error foo.py

The above flag will turn all warnings into errors.

For more complex usage Doug Hellman has a good write up: http://doughellmann.com/PyMOTW/warnings/

Thursday, April 26, 2012

Enabling Upstart user jobs to start at boot.

I've come across an issue with Upstart – user jobs' start on stanzas aren't honored at boot time.

The real issue is more general: user jobs aren't loaded into Upstart until the user creates an Upstart session. If a job isn't loaded into Upstart, it's basically invisible and hence its start on stanzas won't be honored.

Loading user jobs into Upstart is simple. It happens automatically when a user creates an Upstart session by connecting via D-Bus using initctl or one of the shortcuts (e.g. start or status). Until user jobs are loaded into Upstart, they're completely disabled.

So the problem at boot time is that user's don't have the opportunity to create an Upstart session prior to the rc-sysinit job emitting runlevel, this makes it impossible for user jobs with start on runlevel [2345] to be honored.

Perhaps this is by design – I'm not sure – but I wrote the following job to get around the issue by blocking rc-sysinit and creating an Upstart session for each user with an .init/ directory in their home:

The following job should be installed into /etc/init/load-user-jobs.conf:

Tuesday, April 10, 2012

Can't exec "dpkg-architecture" … on Ubuntu 11.10

Ran into a puzzling problem today setting up PostgreSQL 9.1. After creating a user and logging in, I was greeted with:

$ psql postgres brad
Can't exec "dpkg-architecture": No such file or directory at /usr/bin/psql line 103.
Use of uninitialized value $multiarch in scalar chomp at /usr/bin/psql line 104.
psql (9.1.3)
Type "help" for help.

postgres=#

It seems the package dpkg-dev wasn't installed for some reason…

Easy fix:

sudo apt-get install dpkg-dev

Monday, April 9, 2012

Compiling Python on OSX 10.8

Python 2.6 – OSX Lion

./configure MACOSX_DEPLOYMENT_TARGET=10.7
make
make install