Tatsh / tatsh-overlay

Personal Gentoo Portage overlay.
https://tatsh.github.io/tatsh-overlay/
GNU General Public License v2.0
35 stars 10 forks source link

net-dns/pihole: can't read /var/lib/pihole/setupVars.conf: No such file or directory #120

Closed Bogdan107 closed 2 years ago

Bogdan107 commented 2 years ago

I have errors:

$ LC_ALL=en_US pihole restartdns
/usr/bin/pihole: line 142: Cannot restart Pi-hole: command not found

$ LC_ALL=en_US pihole logging off
sed: can't read /var/lib/pihole/setupVars.conf: No such file or directory
  [i] Flushing /var/log/pihole.log ...error: error creating stub state file /var/lib/logrotate/pihole: No such file or directory
error: error creating stub state file /var/lib/logrotate/pihole: No such file or directory
Error: in prepare, no such table: queries (1)
/usr/bin/pihole: line 142: Cannot restart Pi-hole: command not found
  [✓] Flushed /var/log/pihole.log
  [✓] Deleted  queries from database
  [i] Disabling logging...
/usr/bin/pihole: line 142: Cannot restart Pi-hole: command not found
  [✓] Logging has been disabled!

$ LC_ALL=en_US pihole logging on 
sed: can't read /var/lib/pihole/setupVars.conf: No such file or directory
  [i] Enabling logging...
/usr/bin/pihole: line 142: Cannot restart Pi-hole: command not found
  [✓] Logging has been enabled!

$ LC_ALL=en_US pihole -f
  [i] Flushing /var/log/pihole.log ...error: error creating stub state file /var/lib/logrotate/pihole: No such file or directory
error: error creating stub state file /var/lib/logrotate/pihole: No such file or directory
Error: in prepare, no such table: queries (1)
/usr/bin/pihole: line 142: Cannot restart Pi-hole: command not found
  [✓] Flushed /var/log/pihole.log
  [✓] Deleted  queries from database

$ pihole arpflush
  [✗] Failed to truncate network_addresses table
  Database location: /var/lib/pihole/pihole-FTL.db
  Output: Error: in prepare, no such table: network_addresses (1)

$ LC_ALL=en_US pihole -g
  [i] Neutrino emissions detected...
  [✗] Pulling blocklist source list into range
  [i] No source list found, or it is empty

  [i] Building tree...
  [✗] Unable to build gravity tree in /var/lib/pihole/gravity.db_temp
  Error: in prepare, no such table: main.gravity (1)
  [i] Number of gravity domains: 0 (0 unique domains)
  [i] Number of exact blacklisted domains: 1
  [i] Number of regex blacklist filters: 0
  [i] Number of exact whitelisted domains: 0
  [i] Number of regex whitelist filters: 0
  [✓] Flushing DNS cache
  [✓] Cleaning up stray matter

  [✓] DNS service is listening
     [✓] UDP (IPv4)
     [✓] TCP (IPv4)
     [✓] UDP (IPv6)
     [✓] TCP (IPv6)

  [✓] Pi-hole blocking is enabled

Message 1: /usr/bin/pihole: line 142: Cannot restart Pi-hole: command not found

What is wrong: pihole script does not know how to restart system service.

Solution in patch:

--- a/usr/bin/pihole     2021-12-15 23:23:12.772600536 +0200
+++ b/usr/bin/pihole    2021-12-15 23:22:58.841775670 +0200
@@ -138,6 +138,8 @@
         svc="service pihole-FTL restart"
     elif command -v systemctl &>/dev/null; then
         svc="systemctl restart pihole-FTL"
+    elif command -v rc-service &>/dev/null; then
+        svc="rc-service pihole-FTL restart"
     else
         "Cannot restart Pi-hole"
         return 1

Message 2: sed: can't read /var/lib/pihole/setupVars.conf: No such file or directory

File /var/lib/pihole/setupVars.conf strictly reuired in pihole script, but this file is not prepared by installer.

Solution, variant 1: create draft file from ebuild script; Solution, variant 2: create null file from init script (like checkpath -o "$command_user" -f /var/lib/pihole/setupVars.conf).

Question: Why /etc/pihole/setupVars.conf file moved into /var/lib/pihole/setupVars.conf inside the ebuild script? I think, that storing setupVars.conf file under /var directory is reasonable for embedded devices, where root filesystem is RO and /var directory is RW. But why ebuild use /var for storing the file, which place is inside the /etc directory?

Message 3: error: error creating stub state file /var/lib/logrotate/pihole: No such file or directory

This file path defined in STATEFILE variable of /usr/lib64/pihole/piholeLogFlush.sh script. Directory /var/lib/logrotate does not exists by default.

Solution in patch:

--- a/usr/lib64/pihole/piholeLogFlush.sh 2021-12-16 00:24:07.946648775 +0200
+++ b/usr/lib64/pihole/piholeLogFlush.sh 2021-12-16 00:24:53.105081056 +0200
@@ -14,7 +14,7 @@
 # In case we're running at the same time as a system logrotate, use a
 # separate logrotate state file to prevent stepping on each other's
 # toes.
-STATEFILE="/var/lib/logrotate/pihole"
+STATEFILE="/var/lib/pihole/logrotate"

 # Determine database location
 # Obtain DBFILE=... setting from pihole-FTL.db

Message 4: Error: in prepare, no such table: queries (1)

This is bug of pihole or pihole-ftl installer, which must prepare pihole-FTL.db structure.

Message 5: _Error: in prepare, no such table: networkaddresses (1)

This is bug of pihole or pihole-ftl installer, which must prepare pihole-FTL.db structure.

Message 6: Error: in prepare, no such table: main.gravity (1)

As gravity table present in gravity.db file, then this is bug of gravity.sh script, which can't find gravity table inside the gravityTEMPfile or gravityOLDfile file.

Tatsh commented 2 years ago

Message 2

Question: Why /etc/pihole/setupVars.conf file moved into /var/lib/pihole/setupVars.conf inside the ebuild script?

Changes occur to it in other places such as the Pi-hole web interface (there is no package for this yet, but I have it running over here). It needs correct access for that to work. It seems more appropriate that files that can change at runtime not be placed /etc.

Solution, variant 1: create draft file from ebuild script;

I will implement this.

Message 3

Will add.

Message 4,5

Will need to add init of pihole-FTL.db.

Message 6

I am getting this issue at times.

As a workaround:

I deleted /var/lib/pihole/gravity.db*, used the old way to add ad lists (by creating a list of URLs at /var/lib/pihole/adlists.list) and then ran pihole -g. The adlists.list file will be moved to migration_backup after this, and without the web interface the only to add a new ad list is to use SQL with sqlite3 gravity.db:

insert into adlist (address) values ('https://someonewhocares.org/hosts/hosts');

Then run pihole -g.

Tatsh commented 2 years ago

Also for later: https://github.com/Tatsh/tatsh-overlay/issues/119#issuecomment-995401530 and #121

Tatsh commented 2 years ago

Back up your setupVars.conf before merging the ebuilds again.

Tatsh commented 2 years ago

Do you have /etc/dnsmasq.conf? If you do, what is the content? Mine is

conf-dir=/etc/pihole/dnsmasq.d

Currently the ebuild does not ship this file.

Bogdan107 commented 2 years ago

Do you have /etc/dnsmasq.conf? If you do, what is the content?

This file contain standart draft content of system installed dnsmasq package. At now all lines are commented there.

Pi-Holed dnsmasq daemon is included into pihole-FTL binary. Why pihol-ed dnsmasq deamon still requires configs/paths of system daemons (about /etc/dnsmasq.conf file)?

Tatsh commented 2 years ago

We can change that path in FTL's code if that is a concern. The default configuration from Pi-hole's end is that a system cannot have DNSMasq and FTL installed at the same time. FTL is based on DNSMasq so it will use the same paths. I moved the general configs to be under /etc/pihole/dnsmasq.d to make it more clear what kind of configs these are.

Tatsh commented 2 years ago

Please try with a clean install and see if you find if any of these bugs remain:

121

120

119

If you find something, file a new issue.