From e281d72555dae2d5b619655ac8ca92ef4e4082cd Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Thu, 26 May 2016 13:07:38 +0200 Subject: [PATCH] Generate and install virtual hosting unit file Idea and some changes taken from @ekohl, thanks! Closes: #2563 --- build-scripts/build-auth-debian | 2 +- build-scripts/build-auth-rpm | 2 ++ .../debian-authoritative/pdns-server.install | 1 + docs/markdown/authoritative/running.md | 29 ++++++++++++++----- pdns/.gitignore | 1 + pdns/Makefile.am | 8 ++++- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/build-scripts/build-auth-debian b/build-scripts/build-auth-debian index 251d8bba2..e9448df2b 100755 --- a/build-scripts/build-auth-debian +++ b/build-scripts/build-auth-debian @@ -44,7 +44,7 @@ export ID="${ID}" export VERSION_ID="${VERSION_ID}" if [ ${ID} = "ubuntu" -a ${VERSION_ID} = "14.04" ]; then - sed -i '/lib\/systemd\/system\/pdns\.service/d' debian/pdns-server.install + sed -i '/lib\/systemd\/system\/pdns@\?\.service/d' debian/pdns-server.install fi fakeroot debian/rules debian/control diff --git a/build-scripts/build-auth-rpm b/build-scripts/build-auth-rpm index fa79415c8..d90dd6626 100755 --- a/build-scripts/build-auth-rpm +++ b/build-scripts/build-auth-rpm @@ -502,6 +502,7 @@ exit 0 %{_mandir}/man1/pdns-zone2ldap.1.gz %{_mandir}/man1/pdnsutil.1.gz %{_unitdir}/pdns.service +%{_unitdir}/pdns@.service %dir %{_libdir}/%{name}/ %{_libdir}/%{name}/librandombackend.so %dir %{_sysconfdir}/%{name}/ @@ -761,6 +762,7 @@ exit 0 %{_mandir}/man1/pdns-zone2ldap.1.gz %{_mandir}/man1/pdnsutil.1.gz %{_unitdir}/pdns.service +%{_unitdir}/pdns@.service %dir %{_libdir}/%{name}/ %{_libdir}/%{name}/librandombackend.so %dir %{_sysconfdir}/%{name}/ diff --git a/build-scripts/debian-authoritative/pdns-server.install b/build-scripts/debian-authoritative/pdns-server.install index 79ea031e2..084d23a8f 100644 --- a/build-scripts/debian-authoritative/pdns-server.install +++ b/build-scripts/debian-authoritative/pdns-server.install @@ -10,3 +10,4 @@ debian/config/pdns.simplebind.conf usr/share/pdns-server/ debian/resolvconf/pdns etc/resolvconf/update.d/ debian/insserv.d/pdns-server etc/insserv.d/ lib/systemd/system/pdns.service +lib/systemd/system/pdns@.service diff --git a/docs/markdown/authoritative/running.md b/docs/markdown/authoritative/running.md index 33f764ad5..d3bae4769 100644 --- a/docs/markdown/authoritative/running.md +++ b/docs/markdown/authoritative/running.md @@ -98,13 +98,17 @@ It may be advantageous to run multiple separate PowerDNS installations on a single host, for example to make sure that different customers cannot affect each others zones. PowerDNS fully supports running multiple instances on one host. -To generate additional PowerDNS instances, copy the init.d script `pdns` to -`pdns-name`, where `name` is the name of your virtual configuration. Must not -contain a - as this will confuse the script. +To generate additional PowerDNS instances, create a `pdns-NAME.conf` in your +configuration directory (usually `/etc/powerdns`), where `NAME` is the name of +your virtual configuration. -When you launch PowerDNS via this renamed script, it will seek configuration -instructions not in `pdns.conf` but in `pdns-name.conf`, allowing for separate -specification of parameters. +Following one of the following instructions, PowerDNS will read its configuration +from the `pdns-NAME.conf` instead of `pdns.conf`. + +## Starting virtual instances with Sysv init-scripts +Symlink the init.d script `pdns` to `pdns-NAME`, where `NAME` is the name of your +virtual configuration. **Note**: `NAME` must not contain a '-' as this will +confuse the script. Internally, the init script calls the binary with the [`config-name`](settings.md#config-name) option set to `name`, setting in motion @@ -116,7 +120,18 @@ When you launch a virtual instance of PowerDNS, the pid-file is saved inside **Warning**: Be aware however that the init.d `force-stop` will kill all PowerDNS instances! -**Warning**: For systems running systemd, virtual hosting is not yet supported. +## Starting virtual instances with systemd +With systemd it is as simple as calling the correct service instance. Assuming your +instance is called `myinstance` and `pdns-myinstance.conf` exists in the configuration +directory, the following command will start the service: +``` +systemctl start pdns@myinstance.service +``` + +Similarly you can enable it at boot: +``` +systemctl enable pdns@myinstance.service +``` # Internals ## How PowerDNS translates DNS queries into backend queries diff --git a/pdns/.gitignore b/pdns/.gitignore index 7ab506045..2f5bc3fa6 100644 --- a/pdns/.gitignore +++ b/pdns/.gitignore @@ -58,5 +58,6 @@ effective_tld_names.dat /dnsmessage.pb.cc /dnsmessage.pb.h /pdns.service +/pdns@.service /pdns.conf-dist /stubquery diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 4742c0b1a..7332a7c80 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -1213,8 +1213,14 @@ if HAVE_SYSTEMD pdns.service: pdns.service.in $(AM_V_GEN)sed -e 's![@]sbindir[@]!$(sbindir)!' < $< > $@ +pdns@.service: pdns.service + $(AM_V_GEN)sed -e 's!/pdns_server!& --config-name=%i!' \ + -e 's!Authoritative Server!& %i!' \ + < $< > $@ + systemdsystemunitdir = $(SYSTEMD_DIR) systemdsystemunit_DATA = \ - pdns.service + pdns.service \ + pdns@.service endif -- 2.40.0