-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dhcp support #20
Open
ohthehugemanatee
wants to merge
23
commits into
shaderecker:master
Choose a base branch
from
ohthehugemanatee:dhcp-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Dhcp support #20
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f26d20d
Include wildcard dns config in sync
ohthehugemanatee 009fd89
Add capabilities to the container per https://github.com/pi-hole/dock…
ohthehugemanatee c6dc143
Fix extra closing fi in pihole_sync script template
ohthehugemanatee 7c4500b
Add hardcoded dhcp check to keepalive script
ohthehugemanatee e8eedab
Refactor check_pihole script
ohthehugemanatee 1ab888d
Move check_pihole to a template
ohthehugemanatee 3695a28
Add ansible vars to check_pihole script
ohthehugemanatee f6b23dd
Add dhcp options to inventory
ohthehugemanatee b1ba41c
Add dhcp options to README
ohthehugemanatee acb5eed
Add explanatory comments to new inventory items
ohthehugemanatee 4b1e1ea
Tell ansible about the check_pihole template
ohthehugemanatee fc44c1c
Add dhcp options to pihole role
ohthehugemanatee a833aff
Explain DHCP options in readme
ohthehugemanatee 59c790a
Change how DHCP_ENABLED var is set in check_pihole.sh
ohthehugemanatee 846106b
Sync leases and the whole dnsmasq directory
ohthehugemanatee ddec71b
Debug ansible template
ohthehugemanatee 9f7a735
Clarify true/false in check_pihole script
ohthehugemanatee f497600
Fix typo
ohthehugemanatee fc449f9
Fix logical error in health check
ohthehugemanatee da8964a
Create dnsmasq config for DHCP/DNS config in pihole role
ohthehugemanatee 5d6fcbe
Only sync gravity every 12 hours
ohthehugemanatee 6d9736a
Increase sync frequency to every 5 minutes.
ohthehugemanatee 0bcaf48
fix wrong user directory in check_pihole
ohthehugemanatee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
## This script checks the health of the pihole container and enables/disables DHCP as needed. | ||
PIHOLE_DIR="/home/{{ ansible_user }}/pihole" | ||
[ "{{ dhcp_server }}" = "true" ] && DHCP_ENABLED=0 || DHCP_ENABLED=1 # enabled=0, disabled=1 | ||
VIP="{{ pihole_vip_ipv4 }}" | ||
DHCP_START="{{ dhcp_start }}" | ||
DHCP_END="{{ dhcp_end }}" | ||
DHCP_GATEWAY="{{ dhcp_router }}" | ||
DHCP_DOMAIN="{{ dhcp_domain }}" | ||
DHCP_LEASE_TIME="{{ dhcp_lease_time }}" | ||
|
||
# Check if the pihole container is healthy (0) or not (1). | ||
[ "$(docker inspect -f "{{ '{{' }}.State.Health.Status{{ '}}' }}" pihole)" = "healthy" ] && HEALTHY=0 || HEALTHY=1 | ||
|
||
# If the container is not healthy, exit 1. | ||
if [ ${HEALTHY} -eq 1 ]; then | ||
exit ${HEALTHY} | ||
fi | ||
|
||
# If DHCP is not enabled, or we don't own the virtual IP | ||
if [ ${DHCP_ENABLED} -eq 1 ] || ! /usr/sbin/ip a |grep -q ${VIP} ; then | ||
# Ensure DHCP is disabled. | ||
if [ -f ${PIHOLE_DIR}/dnsmasq.d/02-pihole-dhcp.conf ]; then | ||
/usr/bin/docker exec -d pihole /usr/local/bin/pihole -a disabledhcp | ||
fi | ||
# Exit with the health status of the container (0). | ||
exit ${HEALTHY} | ||
fi | ||
|
||
# Ensure DHCP is enabled. | ||
if ! [ -f ${PIHOLE_DIR}/dnsmasq.d/02-pihole-dhcp.conf ]; then | ||
/usr/bin/docker exec -d pihole /usr/local/bin/pihole -a enabledhcp "${DHCP_START}" "${DHCP_END}" "${DHCP_GATEWAY}" "${DHCP_LEASE_TIME}" "${DHCP_DOMAIN}" | ||
fi | ||
|
||
# Exit with the health status of the container (0). | ||
exit ${HEALTHY} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,22 +5,30 @@ host_key_check="-o StrictHostKeyChecking=no" | |
target="{{ ansible_user }}@{{ sync_target }}" | ||
sync_dir="{{ ansible_user_dir }}/{{ sync_dir.path }}" | ||
pihole_dir="{{ ansible_user_dir }}/pihole" | ||
dhcp_server="{{ dhcp_server }}" | ||
[ $(ip a | grep {{ sync_target }}) ] && am_master=0 || am_master=1 # If the sync target is on this host, we are the master (0). | ||
|
||
if [[ $(ip a | grep {{ sync_target }}) ]]; then | ||
nice -n 19 sqlite3 $pihole_dir/pihole/gravity.db ".backup $sync_dir/gravity.dump" | ||
fi | ||
|
||
if [[ ! $(ip a | grep {{ sync_target }}) ]]; then | ||
sleep 60 | ||
|
||
RSYNC_GRAVITY=$(rsync -a --info=name -e "ssh $key $host_key_check" $target:$sync_dir/gravity.dump $sync_dir) | ||
if [ $? -eq 0 ]; then | ||
if [ -n "$RSYNC_GRAVITY" ]; then | ||
docker stop pihole | ||
sudo sqlite3 $pihole_dir/pihole/gravity.db ".restore $sync_dir/gravity.dump" | ||
docker start pihole | ||
# If the gravity dump file is more than 12 hours old, sync it. | ||
if [[ -f $sync_dir/gravity.dump ]] && [[ $(find $sync_dir/gravity.dump -mmin +719) ]]; then | ||
# master generates a dump file. | ||
if [[ $am_master -eq 0 ]]; then | ||
nice -n 19 sqlite3 $pihole_dir/pihole/gravity.db ".backup $sync_dir/gravity.dump" | ||
else | ||
# not master waits for the dump, then rsyncs and imports it. | ||
sleep 60 | ||
RSYNC_GRAVITY=$(rsync -a --info=name -e "ssh $key $host_key_check" $target:$sync_dir/gravity.dump $sync_dir) | ||
if [ $? -eq 0 ]; then | ||
if [ -n "$RSYNC_GRAVITY" ]; then | ||
docker stop pihole | ||
sudo sqlite3 $pihole_dir/pihole/gravity.db ".restore $sync_dir/gravity.dump" | ||
docker start pihole | ||
fi | ||
fi | ||
fi | ||
fi | ||
|
||
# not master syncs everything else. | ||
if [[ $am_master -eq 1 ]]; then | ||
|
||
RSYNC_DNS=$(rsync -a --info=name -e "ssh $key $host_key_check" $target:$pihole_dir/pihole/custom.list $sync_dir) | ||
if [ $? -eq 0 ]; then | ||
|
@@ -35,4 +43,29 @@ if [[ ! $(ip a | grep {{ sync_target }}) ]]; then | |
sudo cp --preserve=timestamps $sync_dir/05-pihole-custom-cname.conf $pihole_dir/dnsmasq.d | ||
fi | ||
fi | ||
|
||
RSYNC_WILDCARD=$(rsync -a --info=name -e "ssh $key $host_key_check" $target:$pihole_dir/dnsmasq.d/02-cluster.vert-wildcard.conf $sync_dir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason to sync this file separately when you later on sync the whole dnsmasq.d directory? |
||
if [ $? -eq 0 ]; then | ||
if [ -n "$RSYNC_WILDCARD" ]; then | ||
sudo cp --preserve=timestamps $sync_dir/02-cluster.vert-wildcard.conf $pihole_dir/dnsmasq.d | ||
fi | ||
fi | ||
|
||
RSYNC_LEASES=$(rsync -a --info=name -e "ssh $key $host_key_check" $target:$pihole_dir/pihole/dhcp.leases $sync_dir) | ||
if [ $? -eq 0 ]; then | ||
if [ -n "$RSYNC_LEASES" ]; then | ||
sudo cp --preserve=timestamps $sync_dir/dhcp.leases $pihole_dir/pihole | ||
fi | ||
fi | ||
|
||
if ! [ -d ${pihole_dir}/dnsmasq.d ]; then | ||
mkdir -p ${pihole_dir}/dnsmasq.d | ||
fi | ||
|
||
RSYNC_DNSMASQ=$(rsync -a --info=name -e "ssh $key $host_key_check" --exclude '02-pihole-dhcp.conf' $target:$pihole_dir/dnsmasq.d/* $sync_dir/dnsmasq.d/) | ||
if [ $? -eq 0 ]; then | ||
if [ -n "$RSYNC_DNSMASQ" ]; then | ||
sudo cp --preserve=timestamps $sync_dir/dnsmasq.d/* $pihole_dir/dnsmasq.d | ||
fi | ||
fi | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert those values to the originals please since the shorter sync interval is only needed for dhcp.
Maybe you can provide some example values, that you consider good, in the readme.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least in my experience the dns performance was impaired pretty easily, so I would like to keep the sync jobs to a minimum by default.