stevejenkins / pihole-cloudsync

Syncs blocklists, blacklists, and whitelists across multiple Pi-holes using a private GitHub repo
MIT License
517 stars 104 forks source link

[Suggestion] Provide an option to specify Docker container name and run docker exec to execute pihole -g #17

Closed justinsangoi closed 10 months ago

justinsangoi commented 4 years ago

I just set up a secondary pihole for my home network using Docker and I was looking to use this tool to sync the two together. To make this work with my docker container, I'm planning on running it on my docker host (Ubuntu 20.04) and changing the pihole_dir to match the volume for the pihole dir of the Docker container. This should work fine but the pihole -g command won't be able to run on the host, it has to be directed to the container instead - docker exec <container_name> pihole -g

Note: I considered running docker-compose restart or other docker equivalent command but I don't feel it is necessary, as pihole runs the gravity update on a cron anyway, so restarting the whole container feels like overkill in this use case.

I'm planning on simply replacing the two pihole -g commands in the bash script to said docker command instead, and it should work. Perhaps an option can be included similar to the shared hosts option where you if you specify a container name, it will run the docker exec command instead of simply pihole -g

The only other way I could think of to get this to work for a docker container would be to build your own docker image from the pihole image, but have the dockerbuild bring in Git and this tool. However, that's a bit more complicated - especially for the average user - so I figured adding an option as explained above would be a simple yet effective alternative.

justinsangoi commented 4 years ago

Making those changes appears to have worked, however I missed the service pihole-FTL start and stop lines. I changed them in the initpull and pull functions as follows

-                       $SUDO service pihole-FTL stop
+                       $SUDO docker exec pihole service pihole-FTL stop
                        $SUDO cp $gravity_db $custom_list $pihole_dir
-                       $SUDO service pihole-FTL start
+                       $SUDO docker exec pihole service pihole-FTL start

There is only one error I encountered when doing this, but it didn't seem to cause any issue at all:

/usr/local/bin/pihole-cloudsync$ /usr/local/bin/pihole-cloudsync/pihole-cloudsync --initpull
Shared Hosts Mode DISABLED.
--initpull option detected. Initializing local Git repo for Pull/Download.
[sudo] password for admin:
s6-svc: warning: /var/run/s6/services/pihole-FTL/notification-fd not present - ignoring request for readiness notification
  [i] Neutrino emissions detected...
  [✓] Pulling blocklist source list into range

  [✓] Preparing new gravity database
  ....etc.
stevejenkins commented 3 years ago

I don't run docker, but will you please confirm that this same fix works with v5 of the script? If so, I can include it as an option. :)

justinsangoi commented 3 years ago

Hi Steve,

Apologies it's been a while - life has been hectic. I haven't yet upgraded my baseline v4 scripts to the v5 scripts as I am still using the option in the older version to run as v5 and it's been working this whole time. I should be able to get this update done soonish. Maybe I'll fork and put in a pullreq once I do.

stevejenkins commented 10 months ago

Closing this unless/until we establish it works with v5. Please do a fresh commit if necessary.