diff --git a/createlinks b/createlinks index 6d080c5..f36181e 100755 --- a/createlinks +++ b/createlinks @@ -2,13 +2,15 @@ use esmith::Build::CreateLinks qw(:all); -foreach (qw(root/servers/@ config)) -{ - templates2events("/var/service/dnscache.forwarder/$_", +templates2events("/var/service/dnscache.forwarder/root/servers/@", qw(bootstrap-console-save console-save dns-update smeserver-dnscache-update)); -} templates2events('/var/service/dnscache/root/servers/@', qw(bootstrap-console-save console-save dns-update smeserver-dnscache-update)); +templates2events("/usr/lib/systemd/system/dnscache.forwarder.service.d/51koozali.conf", + qw(bootstrap-console-save console-save dns-update smeserver-dnscache-update)); +templates2events("/usr/lib/systemd/system/dnscache.service.d/51koozali.conf", + qw(bootstrap-console-save console-save dns-update smeserver-dnscache-update)); +event_link("systemd-reload", qw(console-save dns-update), "89") foreach my $event (qw( console-save @@ -41,6 +43,9 @@ event_link("initialize-default-databases", "domain-modify", "00"); #-------------------------------------------------- $event = "smeserver-dnscache-update"; templates2events("/etc/systemd/system-preset/49-koozali.preset", $event); +templates2events("/usr/lib/systemd/system/dnscache.forwarder.service.d/51koozali.conf", $event); +templates2events("/usr/lib/systemd/system/dnscache.service.d/51koozali.conf", $event); +templates2events("/etc/rsyslog.conf", $event); +safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/rsyslog"); event_link("systemd-reload", $event, "89"); - diff --git a/root/etc/e-smith/templates/etc/rsyslog.conf/32dnscache b/root/etc/e-smith/templates/etc/rsyslog.conf/32dnscache new file mode 100644 index 0000000..35708a1 --- /dev/null +++ b/root/etc/e-smith/templates/etc/rsyslog.conf/32dnscache @@ -0,0 +1,6 @@ +#dnscache +:programname, isequal, "dnscache" /var/log/dnscache/dnscache.log +& stop +:programname, isequal, "dnscache.forwarder" /var/log/dnscache.forwarder/dnscache.forwarder.log +& stop + diff --git a/root/etc/e-smith/templates/usr/lib/systemd/system/dnscache.forwarder.service.d/51koozali.conf/20service b/root/etc/e-smith/templates/usr/lib/systemd/system/dnscache.forwarder.service.d/51koozali.conf/20service new file mode 100644 index 0000000..fe9a6e3 --- /dev/null +++ b/root/etc/e-smith/templates/usr/lib/systemd/system/dnscache.forwarder.service.d/51koozali.conf/20service @@ -0,0 +1,10 @@ +[Service] +{ + my $datalimit = $dnscache{'DataLimit'} || "12000000"; + my $c = $dnscache{'CacheSize'} || 10000000; + my $forwarder = (defined $dnscache{'Forwarder'} && $dnscache{'Forwarder'}) ? "FORWARDONLY=1" : ""; + $OUT = "LimitDATA=$datalimit\n"; + $OUT .= 'Environment=\n"; + $OUT .= 'Environment="DATALIMIT='.$datalimit.'" "IP=127.0.0.2" IPSEND=0.0.0.0 '.$forwarder.' CACHESIZE='.$c.' GID=410 UID=410 "ROOT=/var/service/dnscache.forwarder/root"'; +} + diff --git a/root/etc/e-smith/templates/usr/lib/systemd/system/dnscache.service.d/51koozali.conf/20service b/root/etc/e-smith/templates/usr/lib/systemd/system/dnscache.service.d/51koozali.conf/20service new file mode 100644 index 0000000..db76597 --- /dev/null +++ b/root/etc/e-smith/templates/usr/lib/systemd/system/dnscache.service.d/51koozali.conf/20service @@ -0,0 +1,9 @@ +i[Service] +{ + my $datalimit = $dnscache{'DataLimit'} || "3000000"; + my $localip = $config->get('LocalIP'); + my $ListenIP= $dnscache->prop('ListenIP') || $localip->value || "127.0.0.3"; + $OUT = "LimitDATA=$datalimit\n"; + $OUT .= 'Environment="DATALIMIT='.$datalimit.'" "IP='.$ListenIP.'" IPSEND=0.0.0.0 GID=410 UID=410 "ROOT=/var/service/dnscache/root"'; +} + diff --git a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/CACHESIZE b/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/CACHESIZE deleted file mode 100644 index da2dacb..0000000 --- a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/CACHESIZE +++ /dev/null @@ -1,4 +0,0 @@ -{ - my $c = $dnscache{'CacheSize'} || 10000000; - "export CACHESIZE=$c" -} diff --git a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/DATALIMIT b/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/DATALIMIT deleted file mode 100644 index 96cd52e..0000000 --- a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/DATALIMIT +++ /dev/null @@ -1,4 +0,0 @@ -{ - my $datalimit = $dnscache{'DataLimit'} || 12000000; - "DATALIMIT=$datalimit"; -} diff --git a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/FORWARDER b/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/FORWARDER deleted file mode 100644 index dc20e43..0000000 --- a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/FORWARDER +++ /dev/null @@ -1,4 +0,0 @@ -{ - (defined $dnscache{'Forwarder'} && $dnscache{'Forwarder'}) ? - "export FORWARDONLY=1" : ""; -} diff --git a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/IP b/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/IP deleted file mode 100644 index d53a1b6..0000000 --- a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/IP +++ /dev/null @@ -1 +0,0 @@ -export IP=127.0.0.2 diff --git a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/IPSEND b/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/IPSEND deleted file mode 100644 index 10eaab7..0000000 --- a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/IPSEND +++ /dev/null @@ -1 +0,0 @@ -export IPSEND=0.0.0.0 diff --git a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/ROOT b/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/ROOT deleted file mode 100644 index 421a889..0000000 --- a/root/etc/e-smith/templates/var/service/dnscache.forwarder/config/ROOT +++ /dev/null @@ -1 +0,0 @@ -export ROOT=/var/service/dnscache.forwarder/root diff --git a/root/etc/logrotate.d/dnscache b/root/etc/logrotate.d/dnscache new file mode 100644 index 0000000..bc4b8e3 --- /dev/null +++ b/root/etc/logrotate.d/dnscache @@ -0,0 +1,16 @@ +/var/log/dnscache.forwarder/dnscache.forwarder.log +/var/log/dnscache/dnscache.log{ + weekly + rotate 4 + missingok + notifempty + compress + delaycompress + sharedscripts + su root root + create 600 root root + postrotate + /usr/bin/systemctl try-restart dnscache.service dnscache.forwarder.service >/dev/null 2>&1 || true + endscript +} + diff --git a/root/var/service/dnscache/run b/root/sbin/e-smith/systemd/dnscache-pre similarity index 91% rename from root/var/service/dnscache/run rename to root/sbin/e-smith/systemd/dnscache-pre index f3c1a4f..bdf5eaf 100755 --- a/root/var/service/dnscache/run +++ b/root/sbin/e-smith/systemd/dnscache-pre @@ -38,7 +38,7 @@ unless (-f "/var/service/dnscache/seed") or warn("Could not create seed file"); } -open(STDIN, "<./seed") or warn "Failed to redirect input from seed file: $!"; +open(STDIN, "&STDOUT") or warn "Failed to redirect stderr to stdout: $!";; my $config = esmith::ConfigDB->open or die "Could not open config db."; @@ -71,7 +71,7 @@ $ENV{FORWARDONLY} = '1'; $ENV{IP} = $dnscache->prop('ListenIP') || $localip->value; $ENV{IPSEND} = $dnscache->prop('SendIP') || '0.0.0.0'; $ENV{CACHESIZE} = 200000; -$ENV{ROOT} = '/service/dnscache/root'; +$ENV{ROOT} = '/var/service/dnscache/root'; my $domains = esmith::DomainsDB->open or die "Could not open Domains db."; my $nets = esmith::NetworksDB->open or die "Could not open Networks db."; @@ -119,18 +119,18 @@ delegate_domains_2DNS( $domains->get_all_by_prop('type', 'domain-remote') )); -my $datalimit = $dnscache->prop('DataLimit') || 3000000; - -# Ensure that forwarder instance is started -system("sv", "u", "/service/dnscache.forwarder"); - -# http://marc.theaimsgroup.com/?l=djbdns&m=104812086607532&w=2 -$SIG{'PIPE'} = 'IGNORE'; -exec("envuidgid", "dnscache", "softlimit", "-o250", "-d", "$datalimit", - "/usr/local/bin/dnscache") - or die "failed to execute envuidgid/softlimit/dnscache: $!"; -# NOTREACHED -exit (1); +#my $datalimit = $dnscache->prop('DataLimit') || 3000000; +# +## Ensure that forwarder instance is started +#system("sv", "u", "/service/dnscache.forwarder"); +/usr/bin/systemctl restart dnscache.forwarder +# +## http://marc.theaimsgroup.com/?l=djbdns&m=104812086607532&w=2 +#$SIG{'PIPE'} = 'IGNORE'; +#exec("envuidgid", "dnscache", "softlimit", "-o250", "-d", "$datalimit", +# "/usr/local/bin/dnscache") +# or die "failed to execute envuidgid/softlimit/dnscache: $!"; +exit (0); sub allow_networks_2access_cache { diff --git a/root/var/service/dnscache.forwarder/run b/root/sbin/e-smith/systemd/dnscache.forwarder-pre old mode 100644 new mode 100755 similarity index 51% rename from root/var/service/dnscache.forwarder/run rename to root/sbin/e-smith/systemd/dnscache.forwarder-pre index 58d887c..976f478 --- a/root/var/service/dnscache.forwarder/run +++ b/root/sbin/e-smith/systemd/dnscache.forwarder-pre @@ -1,12 +1,9 @@ #! /bin/sh exec 2>&1 -. ./config - +cd /var/service/dnscache.forwarder/ # Ensure that dnscache has source of randomness to initialise its source # port RNG test -f ./seed || /bin/dd if=/dev/urandom bs=128 count=1 of=seed exec<./seed +exit 0 -# http://marc.theaimsgroup.com/?l=djbdns&m=104812086607532&w=2 -trap "" SIGPIPE -exec envuidgid dnscache softlimit -o250 -d "$DATALIMIT" /usr/local/bin/dnscache diff --git a/root/service/dnscache b/root/service/dnscache deleted file mode 120000 index 638d25a..0000000 --- a/root/service/dnscache +++ /dev/null @@ -1 +0,0 @@ -/var/service/dnscache \ No newline at end of file diff --git a/root/service/dnscache.forwarder b/root/service/dnscache.forwarder deleted file mode 120000 index 01df0b8..0000000 --- a/root/service/dnscache.forwarder +++ /dev/null @@ -1 +0,0 @@ -/var/service/dnscache.forwarder \ No newline at end of file diff --git a/root/usr/lib/systemd/system/dnscache.forwarder.service b/root/usr/lib/systemd/system/dnscache.forwarder.service index 73a13d2..52837bd 100644 --- a/root/usr/lib/systemd/system/dnscache.forwarder.service +++ b/root/usr/lib/systemd/system/dnscache.forwarder.service @@ -1,15 +1,24 @@ [Unit] -Description=dnscache.forwarder, +Description=dnscache.forwarder, An iterative DNS forwarder resolver daemon +Documentation=man:dnscache(8) After=network.target -Requires=runit.service +After=networking.service +Requires=network.target [Service] -Type=oneshot +Type=simple +PermissionsStartOnly=true +LimitDATA=12000000 +LimitNOFILE=250 +WorkingDirectory=/var/service/dnscache.forwarder/root +Environment="DATALIMIT=12000000" "IP=127.0.0.2" FORWARDONLY=1 IPSEND=0.0.0.0 CACHESIZE=10000000 GID=410 UID=410 "ROOT=/var/service/dnscache.forwarder/root" ExecStartPre=/sbin/e-smith/service-status dnscache.forwarder -ExecStart=/usr/bin/sv u /service/dnscache.forwarder -ExecStop=/usr/bin/sv stop /service/dnscache.forwarder -ExecReload=/usr/bin/sv t /service/dnscache.forwarder -RemainAfterExit=yes +ExecStartPre=/sbin/e-smith/systemd/dnscache.forwarder-pre +ExecStart=/usr/local/bin/dnscache + +Restart=always +RestartSec=20s +SyslogIdentifier=dnscache.forwarder [Install] WantedBy=sme-server.target diff --git a/root/var/service/dnscache.forwarder/down b/root/usr/lib/systemd/system/dnscache.forwarder.service.d/.gitignore similarity index 100% rename from root/var/service/dnscache.forwarder/down rename to root/usr/lib/systemd/system/dnscache.forwarder.service.d/.gitignore diff --git a/root/usr/lib/systemd/system/dnscache.service b/root/usr/lib/systemd/system/dnscache.service index bd2254d..5bbd5be 100644 --- a/root/usr/lib/systemd/system/dnscache.service +++ b/root/usr/lib/systemd/system/dnscache.service @@ -1,15 +1,26 @@ [Unit] -Description=dnscache, +Description=dnscache, An iterative DNS resolver daemon +Documentation=man:dnscache(8) After=network.target -Requires=runit.service +After=networking.service +Requires=network.target +Wants=dnscache.forwarder.service +#BindsTo= > Requires= > Wants= > Requisite= [Service] -Type=oneshot +Type=simple +PermissionsStartOnly=true +LimitDATA=3000000 +LimitNOFILE=250 +WorkingDirectory=/var/service/dnscache/root +Environment="DATALIMIT=3000000" "IP=192.168.233.1" FORWARDONLY=1 IPSEND=0.0.0.0 CACHESIZE=200000 GID=410 UID=410 "ROOT=/var/service/dnscache/root" ExecStartPre=/sbin/e-smith/service-status dnscache -ExecStart=/usr/bin/sv u /service/dnscache -ExecStop=/usr/bin/sv stop /service/dnscache -ExecReload=/usr/bin/sv t /service/dnscache -RemainAfterExit=yes +ExecStartPre=/sbin/e-smith/systemd/dnscache-pre +ExecStart=/usr/local/bin/dnscache + +Restart=always +RestartSec=20s +SyslogIdentifier=dnscache [Install] WantedBy=sme-server.target diff --git a/root/var/service/dnscache/down b/root/usr/lib/systemd/system/dnscache.service.d/.gitignore similarity index 100% rename from root/var/service/dnscache/down rename to root/usr/lib/systemd/system/dnscache.service.d/.gitignore diff --git a/root/var/service/dnscache.forwarder/env/ROOT b/root/var/service/dnscache.forwarder/env/ROOT deleted file mode 100644 index 07e4cb7..0000000 --- a/root/var/service/dnscache.forwarder/env/ROOT +++ /dev/null @@ -1 +0,0 @@ -/var/service/dnscache/root diff --git a/root/var/service/dnscache.forwarder/log/run b/root/var/service/dnscache.forwarder/log/run deleted file mode 100755 index 57bb2db..0000000 --- a/root/var/service/dnscache.forwarder/log/run +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -#---------------------------------------------------------------------- -# copyright (C) 2005 Mitel Networks Corporation -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# Technical support for this program is available from Mitel Networks -# Please visit our web site www.mitel.com/sme/ for details. -#---------------------------------------------------------------------- - -exec \ - /usr/bin/setuidgid dnslog \ - /usr/bin/multilog t s5000000 \ - /var/log/dnscache.forwarder - diff --git a/root/var/service/dnscache/env/ROOT b/root/var/service/dnscache/env/ROOT deleted file mode 100644 index 07e4cb7..0000000 --- a/root/var/service/dnscache/env/ROOT +++ /dev/null @@ -1 +0,0 @@ -/var/service/dnscache/root diff --git a/root/var/service/dnscache/log/run b/root/var/service/dnscache/log/run deleted file mode 100755 index 6cac752..0000000 --- a/root/var/service/dnscache/log/run +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -#---------------------------------------------------------------------- -# copyright (C) 1999-2003 Mitel Networks Corporation -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# Technical support for this program is available from Mitel Networks -# Please visit our web site www.mitel.com/sme/ for details. -#---------------------------------------------------------------------- - -exec \ - /usr/bin/setuidgid dnslog \ - /usr/bin/multilog t s5000000 \ - /var/log/dnscache - diff --git a/smeserver-dnscache.spec b/smeserver-dnscache.spec index c19ce66..dcc8a32 100644 --- a/smeserver-dnscache.spec +++ b/smeserver-dnscache.spec @@ -4,7 +4,7 @@ Summary: smeserver module to configure dnscache %define name smeserver-dnscache Name: %{name} %define version 11.0.0 -%define release 5 +%define release 6 Version: %{version} Release: %{release}%{?dist} License: GPL @@ -24,6 +24,9 @@ smeserver server enhancement to configure and run dnscache as a caching nameserver %changelog +* Sat Mar 01 2025 Jean-Philippe Pialasse 11.0.0-6.sme +- move to full systemd units [SME: 12878] + * Thu Apr 04 2024 Brian Read 11.0.0-5.sme - Update createlinks to create smeserver-package-update event[SME: 12579] @@ -506,6 +509,19 @@ perl createlinks /sbin/e-smith/create-system-user dnslog 411 \ "DNS log user" /var/log /bin/false +if [ $1 -gt 1 ] ; then + if [ -e /var/service/dnscache/run ] ; then + /usr/bin/sv d dnscache + /usr/bin/sv d dnscache/log + fi + if [ -e /var/service/dnscache.forwarder/run ] ; then + /usr/bin/sv d dnscache.forwarder + /usr/bin/sv d dnscache.forwarder/log + fi +fi +exit 0 + + %post # Remove any left over env/FORWARDONLY file rm -f /var/service/dnscache/env/FORWARDONLY @@ -515,14 +531,11 @@ rm -rf $RPM_BUILD_ROOT (cd root ; find . -depth -print | cpio -dump $RPM_BUILD_ROOT) /sbin/e-smith/genfilelist $RPM_BUILD_ROOT \ --dir /var/service/dnscache 'attr(0755,root,root)' \ - --dir /var/service/dnscache/log 'attr(0755,root,root)' \ - --file /var/service/dnscache/run 'attr(0750,root,root)' \ --file /var/service/dnscache/dnscache-log.pl 'attr(0750,root,root)' \ - --file /var/service/dnscache/log/run 'attr(0750,root,root)' \ --dir /var/log/dnscache 'attr(02755,dnslog,dnslog)' \ --dir /var/log/dnscache.forwarder 'attr(02755,dnslog,dnslog)' \ - --file /var/service/dnscache.forwarder/run 'attr(0750,root,root)' \ - --file /var/service/dnscache.forwarder/log/run 'attr(0750,root,root)' \ + --file /sbin/e-smith/systemd/dnscache-pre 'attr(0750,root,root)' \ + --file /sbin/e-smith/systemd/dnscache.forwarder-pre 'attr(0750,root,root)' \ > %{name}-%{version}-%{release}-filelist echo "%doc COPYING" >> %{name}-%{version}-%{release}-filelist