vmstan / gravity-sync

๐Ÿ’ซ The easy way to synchronize the DNS configuration of two Pi-hole 5.x instances.
https://vmstan.com/gravity-sync/
GNU General Public License v3.0
2.3k stars 131 forks source link

Error when running 'gravity-sync auto' #444

Closed imamouse111 closed 5 months ago

imamouse111 commented 7 months ago

Looking for advice on how to get 'gravity-sync auto' to work in Pihole Docker instance. I can get 'gravity-sync push' to work but 'auto' throws back 'System has not been booted with systemd as init system (PID 1). Can't operate.' And that's after I've already installed systemd.

Here's my basic setup:

Pihole Docker (Openmediavault (Portainer (Pihole + macvlan))) = Primary 192.168.86.222 Pihole Raspi (bare metal) = Secondary 192.168.86.154

Here is my Docker Compose YAML:

services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    ports:
      - 55:53/tcp
      - 55:53/udp
      - 67:67/udp
      - 83:80/tcp
    environment:
      - TZ:$TZ
      - WEBPASSWORD:$PW
      - DNSSEC=true
    volumes:
      - $DATA/pihole/config/etc-pihole:/etc/pihole
      - $DATA/pihole/config/etc-dnsmasq.d:/etc/dnsmasq.d
    cap_add:
      - NET_ADMIN
    restart: unless-stopped
    networks:
      macvlan:
        ipv4_address: "192.168.86.222"

I'm able to install Gravity Sync on the raspi pretty easily using this guide, but installing in the Docker Pihole requires a whole process that involves doing a 'docker exec' into the container and installing the OpenSSH client and systemd, but it eventually worked. I got Gravity Sync to successfully install but I don't want to have to re-do this process everytime I restart the container (suggestions on how to avoid this are welcome).

Per the above guide, I was able to modify the gravity-sync.conf files on each instance as below. I'm not totally confident I've done everything correctly, so these honestly might be my main issue.

Raspi Pihole gravity-sync.conf:

# REQUIRED SETTINGS ##########################

REMOTE_HOST='192.168.86.154'
REMOTE_USER='pi'

# CUSTOM VARIABLES ###########################

# Pi-hole Folder/File Customization - Only need to be customized when using containers
 LOCAL_PIHOLE_DIRECTORY='/etc/pihole'                       # Local Pi-hole data directory
 REMOTE_PIHOLE_DIRECTORY='/etc/pihole'                      # Remote Pi-hole data directory
 LOCAL_DNSMASQ_DIRECTORY='/etc/dnsmasq.d'                # Local DNSMASQ/FTL data directory
 REMOTE_DNSMASQ_DIRECTORY='/etc/dnsmasq.d'               # Remote DNSMASQ/FTL data directory
 LOCAL_FILE_OWNER='999:999'                       # Local file owner for Pi-hole
 REMOTE_FILE_OWNER='999:999'                      # Remote file owner for Pi-hole

# Pi-hole Docker/Podman container name - Docker will pattern match anything set below
# LOCAL_DOCKER_CONTAINER=''                                 # Local Pi-hole container name
 REMOTE_DOCKER_CONTAINER='pihole'                               # Remote Pi-hole container name

# HIDDEN FIGURES #############################
# See https://github.com/vmstan/gravity-sync/wiki/Hidden-Figures

Docker Pihole gravity-sync.conf:

# REQUIRED SETTINGS ##########################

REMOTE_HOST='192.168.86.222'
REMOTE_USER='root'    #Using 'root' because no 'pi' user is detected when I 'id pi'

# CUSTOM VARIABLES ###########################

# Pi-hole Folder/File Customization - Only need to be customized when using containers
 LOCAL_PIHOLE_DIRECTORY='/etc/pihole'                       # Local Pi-hole data directory
 REMOTE_PIHOLE_DIRECTORY='/etc/pihole'                      # Remote Pi-hole data directory
 LOCAL_DNSMASQ_DIRECTORY='/etc/dnsmasq.d'                # Local DNSMASQ/FTL data directory
 REMOTE_DNSMASQ_DIRECTORY='/etc/dnsmasq.d'               # Remote DNSMASQ/FTL data directory
 LOCAL_FILE_OWNER='999:999'                       # Local file owner for Pi-hole
 REMOTE_FILE_OWNER='999:999'                      # Remote file owner for Pi-hole

# Pi-hole Docker/Podman container name - Docker will pattern match anything set below
 LOCAL_DOCKER_CONTAINER='pihole'                                 # Local Pi-hole container name
#REMOTE_DOCKER_CONTAINER=''                               # Remote Pi-hole container name

# HIDDEN FIGURES #############################
# See https://github.com/vmstan/gravity-sync/wiki/Hidden-Figures

If someone can share how they were able to get this to work or point out what I'm doing wrong, I would be eternally grateful. Thanks in advance =)

imamouse111 commented 7 months ago

If it helps...

This is the system response to trying to run 'push':

root@XXXXXXXXX:~# gravity-sync push
โˆž Initializing Gravity Sync (4.0.7)
โœ“ Loading gravity-sync.conf
โœ“ Detecting local Pi-hole installation
โœ“ Detecting remote Pi-hole installation
โœ“ Gravity Sync remote peer is configured
โœ“ Evaluating arguments: PUSH
ยป Remote target pi@192.168.86.154
โœ“ Validating pathways to Pi-hole
โœ“ Validating pathways to DNSMASQ
โœ“ Hashing the remote Gravity Database
โœ“ Comparing to the local Gravity Database
โœ“ Hashing the remote DNS Records
โœ“ Comparing to the local DNS Records
! DNS CNAMEs not detected on the local Pi-hole
! Static DHCP Addresses not detected on the local Pi-hole
! No replication is required at this time
โˆž Gravity Sync PUSH exited after 6 seconds

And this is the response to 'auto':

root@XXXXXXXXX:~# gravity-sync auto
โˆž Initializing Gravity Sync (4.0.7)
โœ“ Loading gravity-sync.conf
โœ“ Detecting local Pi-hole installation
โœ“ Detecting remote Pi-hole installation
โœ“ Gravity Sync remote peer is configured
โœ“ Evaluating arguments: AUTOMATE
โœ“ Customizing service file username
โœ“ Customizing service file executable path
โœ“ Randomizing service timers
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
โœ“ Moving systemd timer into place
โœ“ Moving systemd service into place
โˆž Reloading systemd daemonSystem has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
โœ— Reloading systemd daemon
imamouse111 commented 6 months ago

For anyone else who come across this issue in the future, it seems the Pihole Docker container can not use systemd, which gravity-sync uses to run 'auto'. My solution was to run a cron job on the Docker container every 6hrs with the command 'gravity-sync push' to sync with my bare metal Pihole.

vmstan commented 6 months ago

You shouldn't be installing Gravity Sync inside of the Pi-hole container, but directly on the container host, which it then has logic to manage the container operations. Otherwise whenever you restart/update the image everything about it will be overwritten.

imamouse111 commented 5 months ago

You shouldn't be installing Gravity Sync inside of the Pi-hole container, but directly on the container host, which it then has logic to manage the container operations. Otherwise whenever you restart/update the image everything about it will be overwritten.

So you're saying, if I have a Pihole Docker container on a Linux host, Gravity Sync should be installed on the Linux host? Not the Pihole container?

vmstan commented 5 months ago

Yes

imamouse111 commented 5 months ago

Thank you, I'll try that.

imamouse111 commented 5 months ago

Yes

Just wanted to say thanks again, this absolutely worked. Appreciate your help.