Close

Software - Part I - Installing RethinkDB

A project log for Greenhouse Pi

Solar powered Raspberry Pi measuring greenhouse environmental data and driving some actors

dotpidotDotPiDot 09/04/2016 at 07:550 Comments

Now that the main componets are in place it is time to write something about the software part of the project:

At the core of the Greehouse PI i planned to have a RethinkDB database. It is aJSON based (noSQL) database which is mainly designed for realtime applications. It provides a mechanism called change feeds, which allows to watch any table (actually better called document store) for changes and trigger an action (similar to SQL-Triggers).

To install RethinkDB on the Raspberry it is necessary to compile the DB from source code. This step takes a while (more than 10 hours for me).

Very import is really to increase the Swap space on the Raspberry before starting the RethinkDB built, which is mentioned as a step in the tutorial but there is no detailed description give. Here is how to do it:

sudo nano /etc/dphys-swapfile
You will see the default value in the file:
CONF_SWAPSIZE=100
Change it to
CONF_SWAPSIZE=1024
and execute
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
That's it - and a
free -m
should give you
total     used     free   shared  buffers   cached
Mem:           435       56      379        0        3       16
-/+ buffers/cache:       35      399
Swap:         1023        0     1023

After the built is done you can change it back to the original value following the same steps.

Now you can start to download and compile RethinkDB.

It is not as complicated as it sounds - you can find a quite good tutorial here:

https://www.rethinkdb.com/docs/install/raspbian/

After the build is done we still need to install the python drivers, which is really easy:

sudo pip install rethinkdb

Now that we have drivers and RethinkDB on the Raspberry we can add RethinkDB to start automatically after reboot (which is not done automatically by the install script).

There is different ways to do it - i decided to add a line to /etc/rc.local:

sudo nano /etc/rc.local
and add one so that it looks like this:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

/your/path/rethinkdb --bind all --server-name rbpi_rethinkdb -d /home/pi --daemon

exit 0
Make sure to add the path to the RethinkDB call - as the script might fail due to missing path settings

Now RethinkDB should be up and running after reboot, drivers are installed and we are good to go...

Also to put the data files of your database to some other location change the path after -d to something you prefer them to be (ideally a usb stick mounted location)

Reboot the system with a

sudo shutdown -r now
and after the system is up again run the foillowing
ps -elf |grep rethinkdb/
1 S root      2692     1  0  80   0 - 26711 -      11:12 ?        00:00:05 /home/pi/rethinkdb/rethinkdb-2.3.4/build/release_system/rethinkdb --bind all --server-name greenhouse_pi -d /home/pi/data --daemon
1 S root      2693  2692  0  80   0 - 13208 -      11:12 ?        00:00:00 /home/pi/rethinkdb/rethinkdb-2.3.4/build/release_system/rethinkdb --bind all --server-name greenhouse_pi -d /home/pi/data --daemon
1 S root      2774  2693  0  80   0 - 13208 -      11:12 ?        00:00:01 /home/pi/rethinkdb/rethinkdb-2.3.4/build/release_system/rethinkdb --bind all --server-name greenhouse_pi -d /home/pi/data --daemon
0 S pi        3538  3516  0  80   0 -   964 pipe_w 12:03 pts/1    00:00:00 grep --color=auto rethinkdb/

which should then give you a very similar result as the above output and tells you RethinkDB is running

Discussions