CouchDB from Src How-To

Well this was more effort than it should have been. I have been dabbling with Erlang for

Media_httpwwwstrangea_gvfsh
a while, and after struggling with MySQL, Tomcat and JDBC I was looking for an alternative web-app stack. CouchDB looks to be perfect, although sufficiently new that there is not a lot of documentation, both of the books available right now are OK, but not brilliant. In general I prefer the style of CouchDB: The Definitive Guide but prefer the examples from Beginning CouchDB. My personal preference with programming and software tool books is that they should provide detailed, hand-held, speak-to-me-like-I-am-an-imbecile walk-throughs of the most common basic use cases. Anyhow, CouchApp looks like a great way to develop apps for CouchDB, although documentation is fairly sparse. The main problem I found is that the versions of Erlang and CouchDB available from repositories for both Ubuntu and Debian are way behind the cutting edge to the point that the examples in the books won't run. I found that the best way to set up my CouchApp development environment is to completely avoid the repositories and build from source in a clean Ubuntu server VM using the following steps:

  • $ apt-get update
  • $ apt-get clean
  • $ apt-get upgrade

We are going to be building some software so the following tools are useful:

  • $ sudo apt-get install build-essential subversion git-core openssh-server

Install Erlang

Install CouchDB

  • $ sudo apt-get build-dep couchdb
  • $ sudo apt-get install xulrunner-dev libicu-dev libcurl4-gnutls-dev libtool
  • $ wget http://mirrors.ukfast.co.uk/sites/ftp.apache.org/couchdb/1.0.0/apache-couchdb...
  • $ tar zxvf apache-couchdb-1.0.0.tar.gz
  • $ cd apache-couchdb-1.0.0
  • $ ./configure
  • $ ./configure --with-js-lib=/usr/lib/xulrunner-devel-1.9.2.3/lib --with-js-include=/usr/lib/xulrunner-devel-1.9.2.3/include
  • $ make CouchDB
  • $make
  • $sudo make install

Final Setup & Running CouchDB

  • $ adduser --system --home /usr/local/var/lib/couchdb --no-create-home --shell /bin/bash --group --gecos "CouchDB Administrator" couchdb
  • $ sudo chown -R couchdb:couchdb /usr/local/etc/couchdb
  • $ sudo chown -R couchdb:couchdb /usr/local/var/lib/couchdb
  • $sudo chown -R couchdb:couchdb /usr/local/var/log/couchdb
  • $sudo chown -R couchdb:couchdb /usr/local/var/run/couchdb
  • $sudo chmod -R 0770 /usr/local/etc/couchdb
  • $sudo chmod -R 0770 /usr/local/var/lib/couchdb
  • $sudo chmod -R 0770 /usr/local/var/log/couchdb
  • $sudo chmod -R 0770 /usr/local/var/run/couchdb
  • $ sudo ln -s /usr/local/etc/init.d/couchdb /etc/init.d/couchdb

Put xulrunner-devel on your LD_LIBRARY_PATH

  • $ sudo touch /etc/ld.so.conf.d/couchdb.conf
  • $ sudo cat > /etc/ld.so.conf.d/couchdb.conf
  • /usr/lib/xulrunner-devel-1.9.2.6 (NB. Check the version that you have installed!)
  • <CTRL-D>
  • $ sudo ldconfig

Running CouchDB Manually

  • $ sudo -i -u couchdb couchdb

Running CouchDB As a Daemon

  • $ sudo /etc/init.d/couchdb start
Posted
 

Argumentative-on-the-go

Media_httpargumentati_dfibz
Most of us experience that moment of having forgotten all of the good arguments that we need to respond to a given point raised during a discussion. Moments after conceding the point it all come flooding back, but too late. To the rescue comes the Skeptical Science iPhone app, well to the rescue of iPhoners anyway. This was covered over at the Boing and I quite liked this comment:

The thing is, there are a LOT of people out there who are just confused and want to know more and don't realize that the common critiques have been addressed by scientists...they're just not experts, or even wanna-be experts and they're a bit lost on things. This could help them

Sometimes people just take a side in an argument that fits with what they know, which might not be much. Once that position is taken it can be very difficult for them to change, especially if it might suggest some ignorance on their part. Tools like this app will at least provide one more way for people to be exposed to the common arguments against climate change and see that those arguments have generally already been thoroughly addressed.

Posted
 

Argumentative-on-the-go

Media_httpwwwstrangea_mgftz
Most of us experience that moment of having forgotten all of the good arguments that we need to respond to a given point raised during a discussion. Moments after conceding the point it all come flooding back, but too late. To the rescue comes the Skeptical Science iPhone app, well to the rescue of iPhoners anyway. This was covered over at the Boing and I quite liked this comment

:

The thing is, there are a LOT of people out there who are just confused and want to know more and don't realize that the common critiques have been addressed by scientists...they're just not experts, or even wanna-be experts and they're a bit lost on things. This could help them

Sometimes people just take a side in an argument that fits with what they know, which might not be much. Once that position is taken it can be very difficult for them to change, especially if it might suggest some ignorance on their part. Tools like this app will at least provide one more way for people to be exposed to the common arguments against climate change and see that those arguments have generally already been thoroughly addressed.

Posted
 

The Editor of "Real Programmers"

The always excellent xkcd has this to say on the subject of editor choice and its relationship to real programmers:
Media_httpac22001comp_zfwyl
It seemed apropo given the last post.
Posted
 

Choosing an Editor

During this morning's lecture I mentioned options for editing on Linux. There are two basic paths that you can go, a GUI editor or a text-based editor. If you go the GUI route then there are many options for notepad type functionality such gEdit on Gnome or kEdit on KDE. However, to really take advantage of Linux you need to learn a proper editor by which I mean a command line editor such as VI (pronounced Vee-Eye), VIM (VI-Improved), or Emacs. Unfortunately the learning curve is very steep on these editors so I can do nothing more than suggest that you try them out and see. Alternatives to the big command-line editors are the lightweight editors like pico or nano that at least give you some on screen help to save you from immediately getting completely lost as is usually the case with VI and Emacs the first time you try it. For interest you should be aware that the VI versus Emacs debate has been going on for many years and is akin to a holy war. Ultimately, our choice of editor is merely a personal decision based upon the needed features and perseverance. That said we can learn a lot from other people's reasons for choosing one editor over another, for example, over at Charlie Stross' blog there was a post a couple of days back about his choice of writing tools (he is one of the best sci-fi writers around at the moment and is part of a very strong Scottish Science Fiction landscape). Charlie is a VI user because Emacs gives him repetitive stress, and given enough time, as one of the commenters pointed out:
Your choice of a text editor is kind of like a tattoo, isn't it? After a while you have to look back on that decision you made when you were fifteen and realize, "yup, that's just never going to go away."
So I am interested to hear your views, especially if you have tried out the editors available in the Ubuntu VM and have settled on one that you will use during the remainder of the module.
Posted
 

Informal Logic Overview

I just found this interesting post introducing the subject of informal logic, a more formal way of describing what we call argumentation theory, or "the stuff what we do in this module". It is a useful but very light overview of how everyday argumentation relates to formal logical reasoning. What is interesting though is that the company whose blog this post is on develops argumentation visualisation software for use in online opinion research and public consultation. It is not as advanced as Araucaria, and delib appears to be taking a different approach to ours in the development of MAgtALO. Nevertheless it looks nice, and that is usually half the battle when getting user uptake, engagement and participation. An example of the kind of argumentation visualisation that the amap software provides:

Posted
 

Araucaria on OS X

There appears to be something wrong with the script included in the Araucaria install images which means that the classpath is not set properly to run Araucaria. This means that although all of the software is included, the JVM cannot find all of the extra jars or other items that the software relies upon to function correctly.To get Araucaria running on OS X, use the following procedure:
  1. Assuming that you have Java 1.5 installed on your Mac (this is the default on recent versions, if you don't have it installed then download and install it), download the Araucaria3_1.dmg file.
  2. Create an Araucaria folder in which you will keep your Araucaria software. This can be located anywhere you like but on the desktop will be fine for now. You can subsequently move it once everything is working.
  3. Open the dmg file, select all of its contents and copy them into your new Araucaria folder.
  4. Create a new text file called araucaria.sh and save it into your new Araucaria folder.
  5. Edit araucaria.sh to contain the following script:
    #!/bin/bash
    java -Xmx96m -cp ./jars/mm.mysql-2.0.4-bin.jar:./jars/jai_codec.jar:./jars/Araucaria3_1.jar Araucaria
  6. Make araucaria.sh executable:
    $ chmod 700 araucaria.sh
  7. Run araucaria.sh
    $ ./araucaria.sh
  8. You should now see something similar to the following
Media_httpwwwstrangea_cbzao
Posted
 

Debian Install with RAID 1

Whilst I use LVM without RAID to manage the drives on my media server, because the media rarely changes so the offline backup is easy to keep in sync, I have started using RAID 1 to mirror the contents of my file server to guard against the failure of a single drive. This is because the data changes sufficiently often on the file server that my regular backup might get out of sync by up to a day which could lose me a days work.
  1. Using the Debian alternate install CD, at the partion disks screen, select manual
  2. Select the free space on your first drive and create 3 new partitions as follows: 2GB for /boot, 2GB for SWAP, Remainder for /
  3. Select "physical volume for RAID" at this point and ensure that the boot partition is marked as bootable.
  4. Repeat the above steps for the second drive
  5. Now select "Configure software RAID" from the main partition disks screen
  6. Create 3 Multidisk (MD) devices with each configured as RAID 1 with 2 active and 0 hotspace disks, one MD device for each of the boot swap and root partitions. Select the correct corresponding matched partitions to include in each MD device, e.g. sda1 and sdb1, sda2 and sdb2, sda3 and sdb3
  7. After returning once more to the main Partition Disks screen you should see the RAID devices that you just created listed alongside the partitions from before. Create file systems on each RAID device in the same fashion as for normal, non-RAID, partitions, e.g. RAID device #0: type ext3 mounted at /boot, RAID device #1: type SWAP, RAID device #2: type ext3 mounted at /
  8. Write the changes to disk and continue with a normal installation
After installation you must also install grub to the master boot record on the second drive in the RAID array so that the system can boot from the other drive in the case of one drive failing.
$ sudo grub-install /dev/sda $ sudo grub grub> device (hd0) /dev/sdb grub> root (hd0,0) grub> setup (hd0) grub> quit
Verify that you have the correct filesystems in the correct places, e.g.
$ grep /dev/md /etc/fstab $ df -h /
The status of RAID devices can be checked using the /proc/mdstat file. Each mdN device contains two sdXN disks and each mdN device should have "2/2" and "UU":
$ cat /proc/mdstat
The mdadm utility gives more details:
$ sudo mdadm --query --detail /dev/md0
Posted
 

Logical Volume Management on Ubuntu

An aide memoire to myself for setting up Ubuntu with LVM at install time:
  1. At the disk partitioning screen select Manual
  2. Select a drive (if they are new drives then they will require partition tables)
  3. Select free space on the drive and choose to create a new partition. First off we need a /boot partition of 100MB which is of the primary type and starts at the beginning of the disk. Select the /boot mount point for this partition and ensure that you have selected the bootable flag.
  4. Repeat the last step to create a SWAP partition of about twice the size of your RAM.
  5. The rest of the disks holding the /boot and SWAP partitions can now be used to hold an LVM containing the / filesystem for the machine.
  6. Select the free space on your first disk.
  7. Choose to make it a physical volume for LVM
  8. Repeat this step for any other drives that will be part of the LVM
  9. Select "Configure the Logical Volume Manager"
  10. Select "Create volume group"
  11. Give the group a name - this can be anything but should be easy to remember. I just used machinename_vg1
  12. Select which physical volumes will be part of the volume group
  13. Select "Create a logical volume"
  14. Select the volume group that will contain the new logical volume
  15. Name the logical volume, e.g. machinename_lv1
  16. Enter the size for the logical volume
  17. Select finish
  18. In the main menu select the volume group
  19. Select to use the volume as Ext3
  20. Select to mount the volume as the / file system
  21. Finish the regular Ubuntu install
Of course one gotcha with LVM appears to be that unless you are combining the volumes with RAID then you could lose your entire logical volume, spanned acroos all of the disks, if you lose a single physical volume to a hardware fault. I would like to be proven wrong on this, and don't want to find out the hard way so I don't currently have data solely in an LVM file system - I merely use it as a convenience for a live file system that is completely backup up elsewhere.
Posted
 

Zen & the Art of the Computer Desktop

Media_httpwwwstrangea_ddujr
I was fed up with all of the mounted network drives appearing on my desktop so finally got around to turning them off. This is my default setup on my macbook but I hadn't set the same behaviour on Ubuntu. Luckily I was spurred to fix this by an article on zenhabits. The process is straightforward:
  1. Start the Gnome Configuration Editor $ gconf-editor
  2. Navigate to /apps/nautilus/desktop/
  3. Set the volumes_visible tickbox to false to turn off the visibility of mounted volumes
You can go further and turn off all of the desktop icons which is very neat but interferes with conky which is bad as conky is my new favourite thing at the moment:
  1. Start the Gnome Configuration Editor $ gconf-editor
  2. Navigate to /apps/nautilus/preferences/
  3. Set the show_desktop tickbox false to turn off the visibility of files stored in the /home/$user/Desktop directory.
Posted