Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Installing

Michael Stanclift edited this page Oct 21, 2020 · 28 revisions

Please make sure you've read over the System Requirements prior to beginning your installation.

Primary Pi-Hole

Minimal preperation is required on your primary Pi-hole, the installer will mostly check that all dependencies have been met for use.

Login to your primary Pi-hole, and run the following command:

export GS_INSTALL=primary && curl -sSL https://raw.githubusercontent.com/vmstan/gravity-sync/master/prep/gs-install.sh | bash

This will verify you have everything necessary to use Gravity Sync. It will also add a passwordless sudo configuration file for the current user. The installer will then exit, and direct you to proceed to the secondary Pi-hole.

After you have completed this step, log out of the primary Pi-hole.

Secondary Pi-Hole

From this point forward, all operations will take place on your secondary Pi-hole.

Login to your secondary Pi-hole, and run the following command:

export GS_INSTALL=secondary && curl -sSL https://raw.githubusercontent.com/vmstan/gravity-sync/master/prep/gs-install.sh | bash

This will verify you have everything necessary to use Gravity Sync. The installer will then use Git to make a copy of the Gravity Sync executables in the folder the installer was executed in, and direct you to proceed to Configuration step below. Once this has completed, you will now have a folder called gravity-sync in your installed directory. Everything Gravity Sync runs from there.

Proceed to the Configuration section.

Configuration

After you install Gravity Sync to your secondary Pi-hole you will need to create a configuration file. This will run automatically by the installer.

This will guide you through the process of:

  • Specifying the IP or DNS name of your primary Pi-hole.
  • Specifying the SSH username to connect to your primary Pi-hole.
  • Configuring your key-pair and applying it to your primary Pi-hole.

The configuration will be saved as gravity-sync.conf in the same folder as the script. If you need to make adjustments to your settings in the future, you can edit this file or run the configuration tool to generate a new one.

If you are deploying Gravity Sync to a system using Docker containers, the script should detect this and prompt for additional configuration. You can also choose to perform an advanced installation when prompted.

After you're pleased with your configuration, proceed to the Execution phase.

Execution

Now, test Gravity Sync. You can run a comparison between primary and secondary databases, which will be non-disruptive, and see if everything has been configured correctly.

./gravity-sync.sh compare

Assuming Gravity Sync runs successfully, it will indicate if there are changes pending between the two databases. If not, make a subtle change to a allow/block list on your primary Pi-hole, such as changing a description field or disabling a allow list item, and then running ./gravity-sync.sh compare again to validate your installation is working correctly.

The Sync

The default command for Gravity Sync is simple.

./gravity-sync.sh

But you can also run ./gravity-sync.sh smart if you feel like it, and it'll do the same thing.

Gravity Sync will perform some checks to help ensure success and then stop before making changes if it detects an issue. It will also perform the same compare function outlined above, and if there are no changes pending, it will exit without making an attempt to copy data.

Example: If the gravity.db has been modified on the primary Pi-hole, but the custom.list file has been changed on the secondary, Gravity Sync will now do a pull of the gravity.db then push custom.list and finally restart the correct components on each server. It will also now only perform a sync of each component if there are changes within each type to replicate. So if you only make a small change to your Local DNS settings, it doesn't kickoff the larger gravity.db replication.

This allows you to be more flexible in where you make your configuration changes to block/allow lists and local DNS settings being made on either the primary or secondary, but it's best practice to continue making changes on one side where possible. In the event there are configuration changes to the same element (example, custom.list changes at both sides) then Gravity Sync will attempt to determine based on timestamps on what side the last changed happened, in which case the latest changes will be considered authoritative and overwrite the other side. Gravity Sync does not merge the contents of the files when changes happen, it simply overwrites the entire content.

If the execution completes, you will now have a synchronized copy of your running gravity.db and custom.list on the both Pi-hole after creating a time-stamped copy of the running files (with .backup appended) in the backup subfolder located with your script, on the secondary Pi-hole.

Finally, a file called gravity-sync.log will be created in the gravity-sync folder along side the script with the date the script was last executed appended to the bottom.

You can check for successful pull attempts by running: ./gravity-sync.sh logs

Automation

Automation of sync is accomplished by adding an execution of the script to the user's crontab file. As Gravity Sync won't make any changes if it doesn't detect a difference to sync, then the impact should be minor to your systems.

./gravity-sync.sh automate

Select the frequency per hour (in minutes) that you'd like to sync and that's it.

Now, make another small adjustment to your primary settings and wait until anointed time to see if your changes have been synchronized. If so, profit! If not, start from the beginning. From this point forward any block list changes you make to the primary will reflect on the secondary within the frequency you select.

If you'd like to see the log of what was run the last crontab, you can view that output by running:

./gravity-sync.sh cron

Keep in mind if your cron task has never run, you will not see any valid output from this command.

Adjusting Automation

You can verify your existing automation entry by running crontab -l and see it listed at the bottom of the crontab file. If you decide to remove or change your frequency (as of version 1.8.3) you can run ./gravity-sync.sh automate again and pick a new timing, including setting it to 0 to disable automation.

Clone this wiki locally