I want to set up cronjobs for these shellscripts - but I'm not sure how to do it in a docker environment in the container so that it will persist in the future.
Another option is to use the host cron job, but use docker exec to execute the command inside the container:
docker exec <Pi-hole_container_name> <command>
Examples:
# In this case, the container name is "Pihole"
docker exec Pihole pihole -b youtube.com fortnite.com
docker exec Pihole pihole -b -d youtube.com fortnite.com
#!/bin/bash
crontab /scripts/crontab.txt
service cron start
exec "$@"
It was chatgpt that gave me this suggestion. However, pihole crashes:
...
[i] Enabling Query Logging
[i] Testing lighttpd config: Syntax OK
[i] All config checks passed, cleared for startup ...
[i] Docker start setup complete
[i] pihole-FTL (no-daemon) will be started as pihole
s6-rc: info: service _startup successfully started
s6-rc: info: service pihole-FTL: starting
s6-rc: info: service pihole-FTL successfully started
s6-rc: info: service lighttpd: starting
s6-rc: info: service lighttpd successfully started
s6-rc: info: service _postFTL: starting
s6-rc: info: service _postFTL successfully started
Checking if custom gravity.db is set in /etc/pihole/pihole-FTL.conf
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
Stopping cron
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service _postFTL: stopping
s6-rc: info: service _postFTL successfully stopped
s6-rc: info: service lighttpd: stopping
Stopping lighttpd
s6-rc: info: service lighttpd successfully stopped
s6-rc: info: service pihole-FTL: stopping
Stopping pihole-FTL
Terminated
s6-rc: info: service pihole-FTL successfully stopped
s6-rc: info: service _startup: stopping
s6-rc: info: service _startup successfully stopped
s6-rc: info: service _uid-gid-changer: stopping
s6-rc: info: service _uid-gid-changer successfully stopped
s6-rc: info: service cron: stopping
Stopping cron
s6-rc: info: service cron successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped
What could be wrong?
Note: If i manually do 'crontab /scripts/crontab.txt' inside the container, everything is working as expected. However, it would be great if this command could be executed automatically.
(I will use the script to block domains for the whole family, including me. My kids are between 13-17 years old - they know how to bypass pihole, but we have an agreement - and this solution will help. Regarding TTL that is not a big issue for us. blocking does not have to be exact)