e31e76d
From 683028b4f5dcf7fb443c85f331e319123f0027a5 Mon Sep 17 00:00:00 2001
5fc4ba0
From: Jiri Popelka <jpopelka@redhat.com>
e31e76d
Date: Wed, 1 Apr 2015 13:14:57 +0200
5fc4ba0
Subject: [PATCH] Systemd service unit files.
5fc4ba0
5fc4ba0
As of August 2014, all Linux distributions include systemd and most of
5fc4ba0
them enable it by default.
5fc4ba0
https://en.wikipedia.org/wiki/Systemd#Adoption
5fc4ba0
5fc4ba0
There are many systemd HOWTOs, like:
5fc4ba0
https://wiki.archlinux.org/index.php/systemd
5fc4ba0
https://coreos.com/docs/launching-containers/launching/getting-started-with-systemd/
5fc4ba0
https://fedoraproject.org/wiki/Packaging:Systemd
5fc4ba0
5fc4ba0
For description of options in the service files, see:
5fc4ba0
http://www.freedesktop.org/software/systemd/man/systemd.unit.html
5fc4ba0
http://www.freedesktop.org/software/systemd/man/systemd.service.html
5fc4ba0
5fc4ba0
Installation of these files is turned on with --enable-systemd
5fc4ba0
configure option. They are installed into
5fc4ba0
PREFIX/lib/systemd/system/ by default. One can also
5fc4ba0
use --with-systemd-unitdir to specify another directory.
5fc4ba0
5fc4ba0
For now the template files reside in src/bin/keactrl/
5fc4ba0
as I haven't figured out a better place.
5fc4ba0
---
5fc4ba0
 configure.ac                             | 12 ++++++++++
5fc4ba0
 src/bin/keactrl/Makefile.am              | 39 ++++++++++++++++++++++++++++++--
5fc4ba0
 src/bin/keactrl/kea-dhcp-ddns.service.in | 12 ++++++++++
5fc4ba0
 src/bin/keactrl/kea-dhcp4.service.in     | 12 ++++++++++
5fc4ba0
 src/bin/keactrl/kea-dhcp6.service.in     | 12 ++++++++++
5fc4ba0
 tools/path_replacer.sh.in                |  4 +++-
5fc4ba0
 6 files changed, 88 insertions(+), 3 deletions(-)
5fc4ba0
 create mode 100644 src/bin/keactrl/kea-dhcp-ddns.service.in
5fc4ba0
 create mode 100644 src/bin/keactrl/kea-dhcp4.service.in
5fc4ba0
 create mode 100644 src/bin/keactrl/kea-dhcp6.service.in
5fc4ba0
5fc4ba0
diff --git a/configure.ac b/configure.ac
e31e76d
index a2b0daf..aa614c0 100644
5fc4ba0
--- a/configure.ac
5fc4ba0
+++ b/configure.ac
e31e76d
@@ -1367,6 +1367,18 @@ if test "x$VALGRIND" != "xno"; then
5fc4ba0
    found_valgrind="found"
5fc4ba0
 fi
5fc4ba0
 
5fc4ba0
+AC_ARG_ENABLE([systemd],
5fc4ba0
+       AS_HELP_STRING([--enable-systemd], [enable systemd support]),
5fc4ba0
+       [use_systemd=$enableval], [use_systemd=no])
5fc4ba0
+AM_CONDITIONAL(USE_SYSTEMD, test "x$use_systemd" != "xno")
5fc4ba0
+AC_SUBST(USE_SYSTEMD)
5fc4ba0
+
5fc4ba0
+AC_ARG_WITH([systemd-unitdir],
5fc4ba0
+       AS_HELP_STRING([--with-systemd-unitdir=PATH],
5fc4ba0
+                      [specify exact directory for systemd service files, defaults to PREFIX/lib/systemd/system/]),
5fc4ba0
+       [SYSTEMD_UNITDIR=$withval], [SYSTEMD_UNITDIR="${prefix}/lib/systemd/system"])
5fc4ba0
+AC_SUBST(SYSTEMD_UNITDIR)
5fc4ba0
+
5fc4ba0
 # Check for optreset in unistd.h. On BSD systems the optreset is
5fc4ba0
 # used to reset the state of getopt() function. Resetting its state
5fc4ba0
 # is required if command line arguments are parsed multiple times
5fc4ba0
diff --git a/src/bin/keactrl/Makefile.am b/src/bin/keactrl/Makefile.am
e31e76d
index c83a597..b494160 100644
5fc4ba0
--- a/src/bin/keactrl/Makefile.am
5fc4ba0
+++ b/src/bin/keactrl/Makefile.am
e31e76d
@@ -32,9 +32,36 @@ endif
7750dd4
 kea.conf: kea.conf.pre
e31e76d
 	$(top_builddir)/tools/path_replacer.sh $(top_srcdir)/src/bin/keactrl/kea.conf.pre $@
5fc4ba0
 
5fc4ba0
+INSTALL_TARGETS = install-empty
5fc4ba0
+
5fc4ba0
 if INSTALL_CONFIGURATIONS
5fc4ba0
 
5fc4ba0
-install-data-local:
5fc4ba0
+INSTALL_TARGETS += install-config-files
5fc4ba0
+
5fc4ba0
+endif
5fc4ba0
+
5fc4ba0
+if USE_SYSTEMD
5fc4ba0
+
5fc4ba0
+EXTRA_DIST += kea-dhcp4.service.in kea-dhcp6.service.in kea-dhcp-ddns.service.in
5fc4ba0
+DISTCLEANFILES += kea-dhcp4.service kea-dhcp6.service kea-dhcp-ddns.service
5fc4ba0
+BUILT_SOURCES += kea-dhcp4.service kea-dhcp6.service kea-dhcp-ddns.service
5fc4ba0
+INSTALL_TARGETS += install-systemd-files
5fc4ba0
+
5fc4ba0
+endif
5fc4ba0
+
5fc4ba0
+kea-dhcp4.service: kea-dhcp4.service.in
e31e76d
+	$(top_builddir)/tools/path_replacer.sh $< $@
5fc4ba0
+
5fc4ba0
+kea-dhcp6.service: kea-dhcp6.service.in
e31e76d
+	$(top_builddir)/tools/path_replacer.sh $< $@
5fc4ba0
+
5fc4ba0
+kea-dhcp-ddns.service: kea-dhcp-ddns.service.in
e31e76d
+	$(top_builddir)/tools/path_replacer.sh $< $@
5fc4ba0
+
5fc4ba0
+install-empty:
5fc4ba0
+	:
5fc4ba0
+
5fc4ba0
+install-config-files:
5fc4ba0
 	$(mkinstalldirs) $(DESTDIR)/@sysconfdir@/@PACKAGE@
5fc4ba0
 	for f in $(CONFIGFILES) ; do	\
5fc4ba0
 	  if test ! -f $(DESTDIR)$(sysconfdir)/@PACKAGE@/$$f; then	\
e31e76d
@@ -42,4 +69,12 @@ install-data-local:
5fc4ba0
 	  fi ;	\
5fc4ba0
 	done
5fc4ba0
 
5fc4ba0
-endif
5fc4ba0
+install-systemd-files:
5fc4ba0
+	$(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNITDIR)
5fc4ba0
+	$(INSTALL_DATA) kea-dhcp4.service $(DESTDIR)$(SYSTEMD_UNITDIR)/kea-dhcp4.service
5fc4ba0
+	$(INSTALL_DATA) kea-dhcp6.service $(DESTDIR)$(SYSTEMD_UNITDIR)/kea-dhcp6.service
5fc4ba0
+	$(INSTALL_DATA) kea-dhcp-ddns.service $(DESTDIR)$(SYSTEMD_UNITDIR)/kea-dhcp-ddns.service
5fc4ba0
+
5fc4ba0
+install-data-local: $(INSTALL_TARGETS)
5fc4ba0
+
5fc4ba0
+uninstall-local: $(UNINSTALL_TARGETS)
5fc4ba0
diff --git a/src/bin/keactrl/kea-dhcp-ddns.service.in b/src/bin/keactrl/kea-dhcp-ddns.service.in
5fc4ba0
new file mode 100644
5fc4ba0
index 0000000..d1e0526
5fc4ba0
--- /dev/null
5fc4ba0
+++ b/src/bin/keactrl/kea-dhcp-ddns.service.in
5fc4ba0
@@ -0,0 +1,12 @@
5fc4ba0
+[Unit]
5fc4ba0
+Description=Kea DHCP-DDNS Server
5fc4ba0
+Documentation=man:kea-dhcp-ddns(8)
5fc4ba0
+Wants=network-online.target
5fc4ba0
+After=network-online.target
5fc4ba0
+After=time-sync.target
5fc4ba0
+
5fc4ba0
+[Service]
5fc4ba0
+ExecStart=@sbindir@/kea-dhcp-ddns -c @sysconfdir@/kea/kea.conf
5fc4ba0
+
5fc4ba0
+[Install]
5fc4ba0
+WantedBy=multi-user.target
5fc4ba0
diff --git a/src/bin/keactrl/kea-dhcp4.service.in b/src/bin/keactrl/kea-dhcp4.service.in
5fc4ba0
new file mode 100644
5fc4ba0
index 0000000..80977d6
5fc4ba0
--- /dev/null
5fc4ba0
+++ b/src/bin/keactrl/kea-dhcp4.service.in
5fc4ba0
@@ -0,0 +1,12 @@
5fc4ba0
+[Unit]
5fc4ba0
+Description=Kea DHCPv4 Server
5fc4ba0
+Documentation=man:kea-dhcp4(8)
5fc4ba0
+Wants=network-online.target
5fc4ba0
+After=network-online.target
5fc4ba0
+After=time-sync.target
5fc4ba0
+
5fc4ba0
+[Service]
5fc4ba0
+ExecStart=@sbindir@/kea-dhcp4 -c @sysconfdir@/kea/kea.conf
5fc4ba0
+
5fc4ba0
+[Install]
5fc4ba0
+WantedBy=multi-user.target
5fc4ba0
diff --git a/src/bin/keactrl/kea-dhcp6.service.in b/src/bin/keactrl/kea-dhcp6.service.in
5fc4ba0
new file mode 100644
5fc4ba0
index 0000000..c24f584
5fc4ba0
--- /dev/null
5fc4ba0
+++ b/src/bin/keactrl/kea-dhcp6.service.in
5fc4ba0
@@ -0,0 +1,12 @@
5fc4ba0
+[Unit]
5fc4ba0
+Description=Kea DHCPv6 Server
5fc4ba0
+Documentation=man:kea-dhcp6(8)
5fc4ba0
+Wants=network-online.target
5fc4ba0
+After=network-online.target
5fc4ba0
+After=time-sync.target
5fc4ba0
+
5fc4ba0
+[Service]
5fc4ba0
+ExecStart=@sbindir@/kea-dhcp6 -c @sysconfdir@/kea/kea.conf
5fc4ba0
+
5fc4ba0
+[Install]
5fc4ba0
+WantedBy=multi-user.target
5fc4ba0
diff --git a/tools/path_replacer.sh.in b/tools/path_replacer.sh.in
5fc4ba0
index 43d7bff..82625ca 100644
5fc4ba0
--- a/tools/path_replacer.sh.in
5fc4ba0
+++ b/tools/path_replacer.sh.in
5fc4ba0
@@ -27,12 +27,14 @@
5fc4ba0
 prefix=@prefix@
5fc4ba0
 sysconfdir=@sysconfdir@
5fc4ba0
 localstatedir=@localstatedir@
5fc4ba0
+sbindir=@sbindir@
5fc4ba0
 
5fc4ba0
 echo "Replacing \@prefix\@ with ${prefix}"
5fc4ba0
 echo "Replacing \@sysconfdir\@ with ${sysconfdir}"
5fc4ba0
 echo "Replacing \@localstatedir\@ with ${localstatedir}"
5fc4ba0
+echo "Replacing \@sbindir\@ with ${sbindir}"
5fc4ba0
 
5fc4ba0
 echo "Input file: $1"
5fc4ba0
 echo "Output file: $2"
5fc4ba0
 
0d5b94e
-sed -e "s@SEP@\@localstatedir\@@SEP@${localstatedir}@SEP@g; s@SEP@\@prefix@@SEP@${prefix}@SEP@g; s@SEP@\@sysconfdir@@SEP@${sysconfdir}@SEP@g" $1 > $2
0d5b94e
+sed -e "s@SEP@\@localstatedir\@@SEP@${localstatedir}@SEP@g; s@SEP@\@prefix\@@SEP@${prefix}@SEP@g; s@SEP@\@sysconfdir\@@SEP@${sysconfdir}@SEP@g; s@SEP@\@sbindir\@@SEP@${sbindir}@SEP@g" $1 > $2
5fc4ba0
-- 
e31e76d
2.3.4
5fc4ba0