RethinkDB on Mac Mini M1 - Install script

Over the past 12 months, I have been working on a Proof of Concept for automative trading software. After developing a few prototypes, it's time to create a single tool that makes it easier to trade, analyze data, and keep track of everything. The first step in this process is to use RethinkDB as the backbone for our data storage and management. In this blog post, I will provide a ready-to-use script to install RethinkDB and give a walkthrough.

Script Walkthrough:

This script is designed for macOS and uses Homebrew as the package manager. It automates the installation and configuration of RethinkDB on your system. Let's break down the steps involved in the script:

  1. Define the RethinkDB data directory path in the DB_PATH variable. This is where the database files will be stored.
  2. Check if Homebrew is installed on the system. If not, the script will install Homebrew automatically.
  3. Install RethinkDB using Homebrew by running. brew install rethinkdb
  4. Stop any running RethinkDB service with brew services stop rethinkdb
  5. Adjust the RethinkDB configuration file. The script creates a backup of the original configuration file, modifies the data directory path, and changes the network bind address to allow connections from the local network. This will make it possible to connect to the RethinkDB server from other devices in the same network.
  6. Change the ownership of the RethinkDB data directory and log file to the current user and the wheel group. This step ensures that the current user can manage the RethinkDB files.
  7. Set RethinkDB to autostart on boot by running brew services start rethinkdb. This command also starts the RethinkDB service immediately. The brew services list command shows the status of the RethinkDB service.
  8. Finally, the script unsets the local DB_PATH variable to clean up the environment.

After running this script, RethinkDB will be installed, configured, and set to start automatically whenever your system boots up. With RethinkDB as the backbone

#!/bin/bash

# 1. Set directory path to a local property
DB_PATH=/Users/lukasztomaszewski/Documents/server2.0/database

# 2. Check if Homebrew is installed
if ! command -v brew &> /dev/null
then
    echo "Homebrew is not installed. Installing now..."
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

# 3. Install RethinkDB with Homebrew
echo "Installing RethinkDB..."
brew install rethinkdb

# 4. Stop any running RethinkDB service
echo "Stopping RethinkDB service..."
brew services stop rethinkdb

# 5. Adjust RethinkDB configuration
echo "Adjusting RethinkDB configuration..."
cp /opt/homebrew/etc/rethinkdb.conf /opt/homebrew/etc/rethinkdb.conf.backup
sed -e "s|directory=/opt/homebrew/var/rethinkdb|directory=$DB_PATH|" \
    -e 's|# bind=127.0.0.1|bind=all|' \
    /opt/homebrew/etc/rethinkdb.conf.backup > /opt/homebrew/etc/rethinkdb.conf

# 6. Change ownership of RethinkDB data directory and log file
echo "Changing ownership of RethinkDB data directory and log file..."
sudo chown -R $USER:wheel $DB_PATH /opt/homebrew/var/rethinkdb

# 7. Set RethinkDB to autostart on boot
echo "Setting RethinkDB to autostart on boot..."
brew services start rethinkdb
brew services list

# 8. Unset local property
unset DB_PATH