Commit Graph

39 Commits

Author SHA1 Message Date
MichaIng 81927334f2
Add native systemd service
Inspired by: https://github.com/pi-hole/pi-hole/pull/2112

A pre-start and a post-stop script are added to reduce doubled setup and cleanup code.

Since systemd services do not natively support dynamic users, test once whether capabilities are supported during install/update, and remove User=pihole otherwise.

Signed-off-by: MichaIng <micha@dietpi.com>
Co-authored-by: DL6ER <dl6er@dl6er.de>
2022-10-30 19:40:33 +01:00
Christian König 3d01e4d0cf No detour - use pihole-FTL.conf to get the API port number
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-09-26 22:55:30 +02:00
Dan Schaper 989c52ef24
Exit with return code if ftl does not start
Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
2022-08-04 17:20:39 -07:00
Christian König 3327df8d9c
Ensure user defined FTL_PID_FILE and FTL_PORT_FILE dirs are created on startup
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-08-04 14:47:43 +02:00
Christian König 7b77d991df
Move FTL port and PID functions to utils.sh
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-07-26 14:38:03 +02:00
DL6ER 98c238064e
Change FTL's default log file path from /var/log/pihole/pihole-FTL.log to /var/log/pihole/FTL.log
Signed-off-by: DL6ER <dl6er@dl6er.de>
2022-07-03 18:43:45 +02:00
Christian König 954a0c2a14
Remove read permission for others on senible log files
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-06-19 23:09:05 +02:00
yubiuser 3fa8f76d99
Combine mkdir in service file
Co-authored-by: MichaIng <micha@dietpi.com>
2022-05-29 16:15:18 +02:00
Christian König ce8731b746
no-dereference
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-05-18 22:19:19 +02:00
Christian König 08faf21b2e
Set file owner and permission to symlinks
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-05-18 22:06:36 +02:00
Christian König 2dd08f070e
Fix copy&paste error
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-05-15 23:30:02 +02:00
Christian König 0961103933
Add backward compatibility to FTL service by creating symlinks
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-05-15 22:10:40 +02:00
Adam Warner 36dd533ef3 use directory /var/log/pihole/ for log storage
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2022-05-15 06:46:23 +02:00
yubiuser 0decc1252b
Respect user configurable path for pid and port file in pihole-FTL.service (#4680)
* Use pid file in pihole-FTL.service

Signed-off-by: Christian König <ckoenig@posteo.de>
Co-authored-by: MichaIng <micha@dietpi.com>
2022-05-11 16:03:44 -07:00
Dan Schaper b714c4598a
Found it.
Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
2022-04-01 14:49:30 -07:00
Dan Schaper 0f192998eb
Create empty files.
Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
2022-04-01 14:17:57 -07:00
Dan Schaper 8a5c7dec71
Ensure existing files are proper owner and mode.
Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
co-authored-by: RD WebDesign <github@rdwebdesign.com.br>
2022-04-01 14:08:09 -07:00
yubiuser 3c41ec08a3
Set file permission for querie database in pihole-FTL.service (#4328)
* Set file permission for querie database in pihole-FTL.service

Signed-off-by: Christian König <ckoenig@posteo.de>

* Use -f flag for chmod of the macvendor.db

Signed-off-by: Christian König <ckoenig@posteo.de>

* Fix missing space

Signed-off-by: Christian König <ckoenig@posteo.de>

* Fix spelling

Signed-off-by: Christian König <ckoenig@posteo.de>
2021-10-08 22:54:23 +01:00
Adam Warner 62f29ba3fa
Merge branch 'release/v5.4' into development 2021-09-11 21:35:11 +01:00
DL6ER a1ee7d92a9
Add possibly missing capabilities
Signed-off-by: DL6ER <dl6er@dl6er.de>
2021-09-06 22:38:16 +02:00
Adam Warner c88c943cda
Merge branch 'release/v5.4' into dev-release5.4
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2021-08-13 20:24:35 +01:00
Adam Warner 913dcead7f
move chmod/chown of macvendor.db to pihole-FTL.service
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2021-08-05 19:02:36 +01:00
MichaIng 57c40cbd09 Update pihole-FTL.service
Make this script a bourne shell script, which requires the removal of only a single bashism, the "{n..m}" expansion. Furthermore, since POSIX echo has no reliable command line options, switch to printf when line breaks shall be omitted. On most distros/setups "sh" calls a much lighter bourne shell like dash, which inits and runs much faster than bash.

Remove unused PIDFILE variable, remove the single case of FTLUSER call and remove it as well. Using variables here might give the wrong impression that there is a change these can be varied. But both are hardcoded in many places throughout Pi-hole, so in this service script.

Consolidate and merge the commands to pre-create and set permissions for required files and directories. The /var/log/pihole directory is and was never used, the touch, chmod and chown call can be merged into one each to reduce overhead. Use "-f" option to to fail on missing database files instead of redirecting STDERR, which is otherwise helpful to debug other possible errors, like missing or corrupted commands, filesystem errors and such.

Do not use "which pihole-FTL" when setting capabilities when the hardcoded path /usr/bin/pihole-FTL is used for the actual daemon call. It makes sense to use the full path here, as the Pi-hole installer and updater installs it explicitly there, and so we prevent users from e.g. overriding it via /usr/local/bin/pihole-FTL too easily.

On pgrep and pkill calls, add the "-x" flag to assure that only "pihole-FTL" is matched and not "foo-pihole-FTL" or "pihole-FTL-bar".

Do not remove possible leftovers from previous pihole-FTL processes on start, but on stop instead. Since "start" includes a proceeding "stop" as well, on service start nothing changes, but on service stop, some resources are now freed.

Remove leading "$" from usage message. In bash this was omitted, as $'...' is a special syntax for escape sequence expansion, which is not applicable here. In dash it would be printed literally. To keep previous behaviour, it is hence removed.

Signed-off-by: MichaIng <micha@dietpi.com>
2021-07-24 14:55:54 +02:00
DL6ER 17aabf26f7
Also use pkill/pgrep in the FTL service script
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-07-21 21:21:17 +02:00
DL6ER de8976da7a
Add CAP_SYS_NICE to FTL's capabilities so it can control its own niceness.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2020-05-28 21:18:31 +02:00
MichaIng 5c17e41cf1 Start pihole-FTL after network
"$network" on a systemd-driven OS leads to "After=network-online.target" in the generated systemd unit.
This target is no guarantee that all network interfaces have been fully configured, as it depends on the related network services types, but at least it reduces the risk that those have not fully finished their job when pihole-FTL starts. If this is the case, certain issues can occur:
- https://github.com/pi-hole/pi-hole/issues/2924
- https://discourse.pi-hole.net/t/have-to-pihole-restartdns-after-reboot/28772

Runtime files are now consistently created in "/run" instead of "/var/run". The second is a symlink to the first for backwards compatibility but on none-ancient distro versions one should use "/run", systemd even prints a warnings if service files use "/var/run". The service file used "/run" and "/var/run" both, in cases for the same files/directories before, which does not directly cause issues currently, due to the symlink, but is inconsistent at best.

Signed-off-by: MichaIng <micha@dietpi.com>
2020-05-16 13:38:18 +02:00
Adam Warner ec09b5843c
Merge branch 'development' into fix/do_not_force_local_resolver 2019-12-11 19:09:02 +00:00
DL6ER 620e1e9c73
Do not force nameserver 127.0.0.1 through resolvconf in pihole-FTL.service
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-12-09 12:23:42 +00:00
DL6ER 8a119d72e2
Ensure database permissions are set up correctly by the service script.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-12-09 12:17:55 +00:00
chrunchyjesus 476975540a
make some shebangs comply to posix standard 2019-11-05 22:33:00 +01:00
DL6ER ae98fde321
Try to obtain PID from PIDFILE. If this fails (file does not exist or is empty), fall back to using pidof + awk
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-05-31 09:18:12 +02:00
DL6ER f6213d4f4d
Use last PID in case pidof returns multiple PIDs for pihole-FTL
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-05-30 15:26:27 +02:00
DL6ER 5ca1bfc11c
Delete /dev/shm/FTL-* files on (re)start of pihole-FTL
Signed-off-by: DL6ER <dl6er@dl6er.de>
2019-02-08 15:00:35 +01:00
DL6ER d0125d5aad
Suppress warning if Pi-hole is not used as DHCP server (/etc/pihole/dhcp.leases is not present in this case)
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-11-19 17:38:19 +01:00
DL6ER b9d47d0dd2
Merge pull request #2378 from pi-hole/fix/pihole-FTL-no-caps
Start pihole-FTL as root if capabilities are not supported by the system
2018-08-21 14:11:24 +02:00
DL6ER ec2426b24d
Add clarifying comments
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-08-19 19:55:47 +02:00
DL6ER 5cd3b11391
Start pihole-FTL as root if capabilities are not supported by the system
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-08-19 14:32:19 +02:00
DL6ER d30b565d98
Touch dhcp.leases to ensure it exists. There are some systems out there where the installer didn't finish on the first run and some users don't have this file being created. Although /etc/pihole should be owned by pihole:pihole, pihole-FTL sometimes fails to open this file and - if this is the case and DHCP is enabled - refuses to start altogether.
Signed-off-by: DL6ER <dl6er@dl6er.de>
2018-08-19 13:53:34 +02:00
Dan Schaper b79ff05e29
Move template files to own subdir. Include pihole-FTL.conf in templates.
Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
2018-07-27 15:21:25 -07:00