EngineeringFantasy

Setting up Rethinkdb with Lunchy

Sunday, 27 September 2015

Table of Contents

Rethinkdb is a powerful new NoSQL database that comes with its one web-based admin console. However, its a bit awkward to set up. The installation is not hard when you have a one line homebrew installation or if you prefer to install it as an application, then you can simply use the use their disk image provided as a url download on their OSX installation page. However, the Rethinkdb command line tool is a bit awkward in the sense that it just creates a directory to store your data in the same directory that you launch it. This is a simple tutorial on how to set rethinkdb as a service so that it stores your data in the same place with a proper set of default configurations.

Installation

I would highly recommend using homebrew to install rethinkdb. Its a painless process and gives you full control as to how you use the rethinkdb CLI.

brew install rethinkdb

Now, we are going to install lunchy, which is a wrapper over launchctl, that basically starts and stops our services in a simple manner.[1] [2]

gem install lunchy

Setup

The first thing that we need to do is install the rethinkdb plist file in our LaunchAgents directory. We can do this by firstly creating a file called com.rethinkdb.server.plist and then running lunchy install on that file. My own configuration is shown below.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.rethinkdb.server</string>
  <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/rethinkdb</string>
        <string>-d</string>
        <string>/Users/quazinafiulislam/Library/RethinkDB/data</string>
    </array>
  <key>StandardOutPath</key>
    <string>/Users/quazinafiulislam/Library/Rethinkdb/out.log</string>
  <key>StandardErrorPath</key>
    <string>/Users/quazinafiulislam/Library/Rethinkdb/error.log</string>
  <key>RunAtLoad</key>
  <false/>
  <key>KeepAlive</key>
    <true/>
  <key>LowPriorityIO</key>
    <false/>
</dict>
</plist>

Steps

  • Create a file using the touch command, i.e. touch com.rethinkdb.server.plist, and just paste in the contents.
  • Replace quazinafiulislam with your username in the file.[3]
  • Create a new directory, ~/Library/Rethinkdb. This place will house all your rethinkdb stuff i.e. data, logs etc.
  • Create a new data directory using rethinkdb create -d ~/Library/Rethinkdb/data.
  • The install the file into your LaunchAgents directory using lunchy install com.rethinkdb.server.plist.
  • Once this is done, create two log files using the touch command to create the output log and the error log inside ~/Library/LaunchAgents named out.log and error.log respectively.

This is the express installation, you can of course customize the installation to your needs. For example you can add your own .conf file for rethinkdb.[4] You can then add it as a parameter to your program arguments by adding the following to your ProgramArguments inside of array.

<string>--config-file<string>
<string>/path/to/your/config/file<string>

Feel free to change the plist file to your liking. One other thing that you might want to change is the RunAtLoad key. I've set this to false, but you might want rethinkdb to start up when you log into your system.

Launching

Launching this is quite easy, all you need to do is tell lunchy that you want to start the rethinkdb service.

lunchy start rethinkdb

We can see that the standard output is printed to the out.log file inside of ~/Library/Rethinkdb.[5]

Rethinkdb log

Stopping rethinkdb is also a breeze.

lunchy stop rethinkdb

[1]The Wikipedia Page will give you a good idea of what both launchd and launchctrl are.
[2]If you want to know the difference between a launch agent and a demon, take a look at this article.
[3]Make sure that when you enter the path of a file or folder in a .plist file, you give the complete path without aliases.
[4]Learn to configure rethinkdb from their configuration documentation page. I would strongly encourage you to create your own .conf file.
[5]You can specify your port as another ProgramArgument.