Activate/deactivate groups via cron in v6

Hi!
On the main branch I use a con job to activate and deactivate a group. I am now testing v6 and the same cron job does not seem to work. Is that to be expected? Is there a new way to do the same in v6?
Here is my crontab:
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
0 15 * * * sudo sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 0 where name = 'Kids-Restricted'" && pihole restartdns
0 17 * * * sudo sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 1 where name = 'Kids-Restricted'" && pihole restartdns

Thanks!

No, it should work. How do you discover it's not working? What does the web interface show you about the group's status at this time?

Nothing happens. the group status does not change and I see nothing in the logs.

Another thing I noticed is that the crontab is reset at reboot ie. the lines I added disappear when the container is restarted. To fix that I had to edit /etc/crontabs/root.

Moreover, activating/deactivating a group on the web interface, also fails. gives "bad element ( enabled_2 ) or invalid data-id!”. I am quite sure this was not the case when I tested this on v6 earlier today so might be an unrelated issue.

Okay, so this is likely something else. I'd start with trying to run the commands you want to be run be cron yourself on the terminal and check if there are any error messages.

Ah! A container, this is new information!

Mind that Pi-hole v6.0 is based on Alpine so the issue may be as simple as that sudo is not available and, hence, you commands above probably indeed simply fail (and would have provided a clear error message if tested on the terminal first :wink: ).


I agree this looks unrelated. Can you trigger it reliably? Is there something specify you have to do or does it always happen?

Makes a lot of sense indeed :slight_smile:
Trying the commands directly gives me "bash: sqlite3: command not found” which is fixed by installing sqlite.
the command pihole restartdns gives an error though [âś—] /usr/local/bin/pihole: line 193: service: command not found. Is it needed btw?
The issue with the web interface happens everytime. now on 2 different installs of pihole v6, one on an RPI5 and another on my Mikrotik router and in different browsers.

you could also have used

pihole-FTL sqlite3

without installing the external dependency.

Passing this on to the docker master's, maybe @PromoFaux or @yubiuser already have a fix/suggestion for this.


Thanks. I have been able to reproduce it, the bug fix is here:

https://github.com/pi-hole/web/pull/2922

1 Like

Promofaux abandoned his PR on a mocked service command

https://github.com/pi-hole/docker-pi-hole/pull/1453

I think we had some discussion that this is not needed on docker, as a FTL restart should be done via a container restart.

To re-read the group settings, a real-time signal could be send instead.

1 Like

Great. Thanks!
Another issue I thought I solved but did not is that my crontab gets reset at reboot. I tried via crontab -e, /etc/crontabs/root, /var/spool/cron/crontabs/root and /var/spool/cron/crontabs.224. none of them persists after reboot.

Instead of adding the cron job into the container, you could have it on the host and run the commands with: docker exec -it [name of pihole container] [command]

(maybe - working on theory here!)

1 Like

That’s a great idea. It works great but need to remove the -it flag.
To summarize:

  • crontab -e in the host machine instead of the container
  • add the lines below to the crontab, where ”pihole6" is the name of my pihole container.
0 15 * * * docker exec pihole6 pihole-FTL sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 0 where name = 'Kids-R'" && docker exec pihole6 pkill -SIGRTMIN+0 pihole-FTL
0 17 * * * docker exec pihole6 pihole-FTL sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 1 where name = 'Kids-R'" && docker exec pihole6 pkill -SIGRTMIN+0 pihole-FTL
  • save and exit

Hi,

I'm having similar issue but with a Mitkrotik running a pihole as a container.

when I put the script via crontab -e.... it gets overwrriten after a reboot eventhough I already persisted /etc/crontabs

any suggestions

Those crontab -e jobs are most likely stored on another location:

$ man crontab
[..]
FILES
[..]
       /var/spool/cron/crontabs

I think you'll have more luck asking the MikroTik community for how to make those cronjobs reboot persistent.

looks like its a link to /etc/crontabs

MTKAX3:/# man crontab
bash: man: command not found
MTKAX3:/# cd /var/spool/
MTKAX3:/var/spool# ls
cron mail
MTKAX3:/var/spool# cd cron/
MTKAX3:/var/spool/cron# ls
crontabs
MTKAX3:/var/spool/cron# ls -l
total 0
lrwxrwxrwx 1 root root 13 Feb 13 23:17 crontabs -> /etc/crontabs
MTKAX3:/var/spool/cron#