Pihole Blacklist scripts not working not under Docker

Hi All,

I currently run PiHole as a docker container - see previous post Move from Full Pihole to Docker - #10 by anowak.

Understand PiHole was not intended for parental control but seemed to be the easiest way to prevent access to social media sites during school days.

The idea is to have a cron job run a script twice a week. Once on Monday morning and then on Friday afternoon. This script would enable or disable the gravity database blacklist table based on the comment with the word "script".

Cron Job.

00 6 * * Mon /opt/script/enabledisable_domainlist.sh
30 16 * * Fri /opt/script/enabledisable_domainlist.sh

enabledisable_domainlist.sh

#!/bin/bash

dayofweek="$(date +%w)"
# Monday
if [ ${dayofweek} = "1" ]; then
 enabled=1
# Friday
elif [ ${dayofweek} = "5" ]; then
 enabled=0
else
 exit
fi

gravitydb="/etc/pihole/gravity.db"

# Enable/Disable blacklists with script in comment.
pihole-FTL sqlite3 ${gravitydb} "update 'domainlist' SET enabled = '${enabled}' WHERE comment like '%Script%';"

pihole restartdns reload-lists

Using docker-compose, I inject the initialisation script into /etc/cont-init.d to create the Cron jobs.

Initialisation script

#!/bin/bash

chmod +x /opt/script/enabledisable_domainlist.sh
crontab /opt/script/cron.txt

All seems to work, as the scripts are being triggered correctly and modify the DB.

The issue I am having is that PiHole, even though I have the blocklist enabled through the script - seem to ignore the changes until I manually restart the DNS Service or manually run *pihole restartdns reload-lists*.

I created some logging to see what was happening and the script is being triggered and DB is being updated but it ignores the changes until I manually rung the restart?

root@pihole:/var/log# cat cron.log
Fri Jan 20 16:30:01 AEDT 2023: 0
Fri Jan 20 16:30:01 AEDT 2023: /etc/pihole/gravity.db
Fri Jan 20 16:30:01 AEDT 2023
id  type  domain               enabled  date_added  date_modified  comment
--  ----  -------------------  -------  ----------  -------------  ---------------------
1   3     (.|^)youtube.*$      0        1661230986  1674192601      Script Block YouTube
2   3     (.|^)googlevideo.*$  0        1661230986  1674192601      Script Block YouTube
3   3     .*youtu.?be.*        0        1661230986  1674192601      Script Block YouTube
4   3     (.|^)tiktok.*$       0        1661230986  1674192601      Script Block TikTok
5   3     (.|^)tiktok.com$     0        1661230986  1674192601      Script Block TikTok
6   3     (.|^)twitch.tv$      0        1661230986  1674192601      Script Block Twitch
DNS Restarted
Mon Jan 23 06:00:01 AEDT 2023: 1
Mon Jan 23 06:00:01 AEDT 2023: /etc/pihole/gravity.db
Mon Jan 23 06:00:01 AEDT 2023
id  type  domain               enabled  date_added  date_modified  comment
--  ----  -------------------  -------  ----------  -------------  ---------------------
1   3     (.|^)youtube.*$      1        1661230986  1674414001      Script Block YouTube
2   3     (.|^)googlevideo.*$  1        1661230986  1674414001      Script Block YouTube
3   3     .*youtu.?be.*        1        1661230986  1674414001      Script Block YouTube
4   3     (.|^)tiktok.*$       1        1661230986  1674414001      Script Block TikTok
5   3     (.|^)tiktok.com$     1        1661230986  1674414001      Script Block TikTok
6   3     (.|^)twitch.tv$      1        1661230986  1674414001      Script Block Twitch
DNS Restarted
Fri Jan 27 16:30:01 AEDT 2023: 0
Fri Jan 27 16:30:01 AEDT 2023: /etc/pihole/gravity.db
Fri Jan 27 16:30:01 AEDT 2023
id  type  domain               enabled  date_added  date_modified  comment
--  ----  -------------------  -------  ----------  -------------  ---------------------
1   3     (.|^)youtube.*$      0        1661230986  1674797401      Script Block YouTube
2   3     (.|^)googlevideo.*$  0        1661230986  1674797401      Script Block YouTube
3   3     .*youtu.?be.*        0        1661230986  1674797401      Script Block YouTube
4   3     (.|^)tiktok.*$       0        1661230986  1674797401      Script Block TikTok
5   3     (.|^)tiktok.com$     0        1661230986  1674797401      Script Block TikTok
6   3     (.|^)twitch.tv$      0        1661230986  1674797401      Script Block Twitch
DNS Restarted
Mon Jan 30 06:00:01 AEDT 2023: 1
Mon Jan 30 06:00:01 AEDT 2023: /etc/pihole/gravity.db
Mon Jan 30 06:00:01 AEDT 2023
id  type  domain               enabled  date_added  date_modified  comment
--  ----  -------------------  -------  ----------  -------------  ---------------------
1   3     (.|^)youtube.*$      1        1661230986  1675018801      Script Block YouTube
2   3     (.|^)googlevideo.*$  1        1661230986  1675018801      Script Block YouTube
3   3     .*youtu.?be.*        1        1661230986  1675018801      Script Block YouTube
4   3     (.|^)tiktok.*$       1        1661230986  1675018801      Script Block TikTok
5   3     (.|^)tiktok.com$     1        1661230986  1675018801      Script Block TikTok
6   3     (.|^)twitch.tv$      1        1661230986  1675018801      Script Block Twitch
DNS Restarted
Fri Feb  3 16:30:01 AEDT 2023: 0
Fri Feb  3 16:30:01 AEDT 2023: /etc/pihole/gravity.db
Fri Feb  3 16:30:01 AEDT 2023
id  type  domain               enabled  date_added  date_modified  comment
--  ----  -------------------  -------  ----------  -------------  ---------------------
1   3     (.|^)youtube.*$      0        1661230986  1675402201      Script Block YouTube
2   3     (.|^)googlevideo.*$  0        1661230986  1675402201      Script Block YouTube
3   3     .*youtu.?be.*        0        1661230986  1675402201      Script Block YouTube
4   3     (.|^)tiktok.*$       0        1661230986  1675402201      Script Block TikTok
5   3     (.|^)tiktok.com$     0        1661230986  1675402201      Script Block TikTok
6   3     (.|^)twitch.tv$      0        1661230986  1675402201      Script Block Twitch
DNS Restarted

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.