Auto Update Pi-Hole

crontab -e

add this line to the bottom

0 7 * * * pihole -up

Is it safe to run dist-upgrade, wouldn't that mess up the dns if a new kernel breaks things?

Yeah, I don't think any of the devs would suggest doing that. The additional pihole commands are also not necessary as pihole -g and -f already run automatically.

So stick with the regular apt-get upgrade to keep all packages updated?

so i am not allowed to upgrade my raspberry pi ("Updating and upgrading Raspberry Pi OS - Raspberry Pi Documentation") to the latest version because it can break pihole?

Updating Raspian shouldn't break pi.hole, you can run it on other distros too afaik

We did have some issues when users upgraded from Wheezy to Jessie. For now, I would say upgrade at your own discretion and if you do run into problems, we're around to help.

1 Like

Disclaimer: Don't run this code unless you understand it.


Here is my script to update pihole running RASPBIAN.

sudo apt update
sudo apt -yf dist-upgrade
sudo apt-get -y --purge autoremove
sudo apt-get autoclean
pihole -g -up
pihole -up

The sudo commands update all the packages and remove any old items. The "-g up"updates gravity first and then I update the pihole subsystems later with "-up". One other note, I've found on many pihole systems that you have to run the installer and perform an upgrade in order to get the FTL code.

This is the cron at /etc/cron.d/pihole, installed with pihole:

pi@raspberrypi:~ $ cat /etc/cron.d/pihole
# Pi-hole: A black hole for Internet advertisements
# (c) 2017 Pi-hole, LLC (
# Network-wide ad blocking via your own hardware.
# Updates ad sources every week
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.
# This file is under source-control of the Pi-hole installation and update
# scripts, any changes made to this file will be overwritten when the softare
# is updated or re-installed. Please make any changes to the appropriate crontab
# or other cron file snippets.

# Pi-hole: Update the ad sources once a week on Sunday at a random time in the
#          early morning. Download any updates from the adlists
3 4   * * 7   root    PATH="$PATH:/usr/local/bin/" pihole updateGravity

# Pi-hole: Update Pi-hole! Uncomment to enable auto update
#30 2    * * 7   root    PATH="$PATH:/usr/local/bin/" pihole updatePihole

# Pi-hole: Flush the log daily at 00:00
#          The flush script will use logrotate if available
#          parameter "once": logrotate only once (default is twice)
#          parameter "quiet": don't print messages
00 00   * * *   root    PATH="$PATH:/usr/local/bin/" pihole flush once quiet

@reboot root /usr/sbin/logrotate /etc/pihole/logrotate

# Pi-hole: Grab local version and branch every 10 minutes
*/10 *  * * *   root    PATH="$PATH:/usr/local/bin/" pihole updatechecker local

# Pi-hole: Grab remote version every 24 hours
28 15  * * *   root    PATH="$PATH:/usr/local/bin/" pihole updatechecker remote
@reboot root    PATH="$PATH:/usr/local/bin/" pihole updatechecker remote reboot

Can someone explain why the line to update pihole (#30 2 * * 7 root PATH="$PATH:/usr/local/bin/" pihole updatePihole) is even in there, since uncommenting that line will cause an overwrite the moment an update is actually performed (since the update will overwrite this file, as stated earlier in the file).

The intention is that the user will uncomment it if they want it to auto-update, but it looks like we didn't take into account that it would also be updated! You can always copy the line to a different cron file.


If I've understood the thread correctly, there currently isn't an official/intended way to enable auto-updating of pi-hole (that lasts more than one update)?

So yes, but that's a good thing :slight_smile: