Make location of pihole log files configurable

In /etc/dnsmasq.d/01-pihole.conf, there is an entry log-facility=/var/log/pihole.log, so apparently, this would make the log file location configurable.
Pihole-FTL has no configuration option to make it’s logfile configurable, so it’s always /var/log/pihole-FTL.log

request(s):

  • make the location of /var/log/pihole-FTL.log configurable in /etc/pihole/pihole-FTL.conf
  • modify /etc/init.d/pihole-FTL to make use of the configurable options for both pihole.log and pihole-FTL.log. This file contains hard coded locations for both the log files (touch, chown, chmod).

Apparently, somebody started the work to move the logfiles to a separate folder, but never finished it (mkdir -p /var/log/pihole, chown pihole:pihole /var/log/pihole)

Well … this is already possible using the option LOGFILE=... but is somehow missing in the docs. I will add it there, thanks for pointing this out.

Having configurable paths in the service file (plus additional locations all over the place I assume) will blow up the code significantly. My suggestion was always to create a symlink from the hard-coded location to anywhere you want the files to end up.

1 Like

Thank you for your quick reply.

Would you please explain how to do that (NOT enough Linux knowledge)…

The goal, despite the massive negative comments, is to save the SD card (a bit more), ref this topic.

Sure, see here:

2 Likes

If I understand this correctly, I could make use of the already created folder /var/log/pihole/, created by /etc/init.d/pihole-FTL, but never used,
mount that folder as TMPFS and have the the logs written to the TMPFS (which I will of course loose, if the pi is rebooted. Correct?

Thanks for your time and effort.

Yes. You can also just disable the logs if you don’t need them. You will still have all your data in the database.

Your guide works like a charm, as usual.
Here is the script I used to make the logs move to TMPFS:

#!/bin/bash

# pihole logs
# reference https://discourse.pi-hole.net/t/moving-the-pi-hole-log-to-another-location-device/2041
# add /var/www/html/slate7/pages/text to /etc/fstab
mkdir -p /var/log/pihole
sudo sed -i '$ a tmpfs /var/log/pihole tmpfs nodev,nosuid,gid=pihole,uid=pihole,mode=0755,size=16M 0 0' /etc/fstab
sudo mount /var/log/pihole

sudo service pihole-FTL stop
sudo cp /var/log/pihole.log /var/log/pihole
sudo rm /var/log/pihole.log
sudo cp /var/log/pihole-FTL.log /var/log/pihole
sudo rm /var/log/pihole-FTL.log
sudo ln -s /var/log/pihole/pihole.log /var/log/pihole.log
sudo ln -s /var/log/pihole/pihole-FTL.log /var/log/pihole-FTL.log
sudo service pihole-FTL start

# logrotate
mkdir -p /home/pi/custom-pihole
sudo cp /etc/pihole/logrotate /home/pi/custom-pihole
file=/home/pi/custom-pihole/logrotate
sudo sed -i 's#/var/log#/var/log/pihole#g' $file

# cron
echo "0 0 * * * root /usr/sbin/logrotate --force --state /var/log/pihole/status /home/pi/custom-pihole/logrotate" | sudo tee /etc/cron.d/custom-pihole
echo "@reboot root /usr/sbin/logrotate --state /var/log/pihole/status /home/pi/custom-pihole/logrotate" | sudo tee -a /etc/cron.d/custom-pihole

edit
modified the cron jobs, explanation, see next entry.
/edit

I used /home/pi/custom-pihole as the destination for the new logrotate to avoid conflicts with pihole -up and pihole -r

Thanks again for your time and effort.

Found a problem with logrotation, decribed in this article.

I started getting daily messages:

error: error renaming temp state file /var/lib/logrotate/status.tmp

I assumed this was caused by having both the original pihole logrotate and the new custom logrotate run @ midnight (00:00).

I modified the new custom logrotate cron job:

0 0 * * * root /usr/sbin/logrotate --force --state /var/log/pihole/status /home/pi/custom-pihole/logrotate
@reboot root /usr/sbin/logrotate --state /var/log/pihole/status /home/pi/custom-pihole/logrotate

This will create a separate state file /var/log/pihole/status.
The error disappeared (tested several days).

It should also be noted the cron @reboot job is useless when using TMPFS, since there will be no logfiles in that location after a reboot.