5fc4ba0
diff --git a/configure.ac b/configure.ac
1713070
index 46780d5..43c57b1 100644
5fc4ba0
--- a/configure.ac
5fc4ba0
+++ b/configure.ac
1713070
@@ -1152,6 +1152,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
1713070
diff --git a/tools/path_replacer.sh.in b/tools/path_replacer.sh.in
1713070
index f444afc..2ce8b3b 100644
1713070
--- a/tools/path_replacer.sh.in
1713070
+++ b/tools/path_replacer.sh.in
1713070
@@ -19,12 +19,14 @@
1713070
 prefix=@prefix@
1713070
 sysconfdir=@sysconfdir@
1713070
 localstatedir=@localstatedir@
1713070
+sbindir=@sbindir@
1713070
 
1713070
 echo "Replacing \@prefix\@ with ${prefix}"
1713070
 echo "Replacing \@sysconfdir\@ with ${sysconfdir}"
1713070
 echo "Replacing \@localstatedir\@ with ${localstatedir}"
1713070
+echo "Replacing \@sbindir\@ with ${sbindir}"
1713070
 
1713070
 echo "Input file: $1"
1713070
 echo "Output file: $2"
1713070
 
1713070
-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
1713070
+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
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]
99e4c5c
+ExecStart=@sbindir@/kea-dhcp-ddns -c @sysconfdir@/kea/kea-dhcp-ddns.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]
99e4c5c
+ExecStart=@sbindir@/kea-dhcp4 -c @sysconfdir@/kea/kea-dhcp4.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]
99e4c5c
+ExecStart=@sbindir@/kea-dhcp6 -c @sysconfdir@/kea/kea-dhcp6.conf
5fc4ba0
+
5fc4ba0
+[Install]
5fc4ba0
+WantedBy=multi-user.target
1f521f8
diff --git a/src/bin/keactrl/Makefile.am b/src/bin/keactrl/Makefile.am
1f521f8
index 9eb3da9..b556fcc 100644
1f521f8
--- a/src/bin/keactrl/Makefile.am
1f521f8
+++ b/src/bin/keactrl/Makefile.am
1f521f8
@@ -50,6 +50,8 @@ kea-ctrl-agent.conf: kea-ctrl-agent.conf.pre
1f521f8
 	$(top_builddir)/tools/path_replacer.sh \
1f521f8
     $(top_srcdir)/src/bin/keactrl/kea-ctrl-agent.conf.pre $@
1f521f8
 
1f521f8
+INSTALL_TARGETS = install-empty
1f521f8
+
1f521f8
 if INSTALL_CONFIGURATIONS
1f521f8
 
1f521f8
 # Since Kea 1.3.0 release we have 4 different Kea configuration files
1f521f8
@@ -60,6 +62,31 @@ if INSTALL_CONFIGURATIONS
1f521f8
 # To preserve any user modifications to the old version of the file,
1f521f8
 # this old file is backed up as keactrl.conf.bak.
1f521f8
 install-data-local:
1f521f8
+INSTALL_TARGETS += install-config-files
1f521f8
+
1f521f8
+endif
1f521f8
+
1f521f8
+if USE_SYSTEMD
1f521f8
+
1f521f8
+EXTRA_DIST += kea-dhcp4.service.in kea-dhcp6.service.in kea-dhcp-ddns.service.in
1f521f8
+DISTCLEANFILES += kea-dhcp4.service kea-dhcp6.service kea-dhcp-ddns.service
1f521f8
+BUILT_SOURCES += kea-dhcp4.service kea-dhcp6.service kea-dhcp-ddns.service
1f521f8
+INSTALL_TARGETS += install-systemd-files
1f521f8
+
1f521f8
+endif
1f521f8
+
1f521f8
+kea-dhcp4.service: kea-dhcp4.service.in
1f521f8
+	$(top_builddir)/tools/path_replacer.sh $< $@
1f521f8
+
1f521f8
+kea-dhcp6.service: kea-dhcp6.service.in
1f521f8
+	$(top_builddir)/tools/path_replacer.sh $< $@
1f521f8
+
1f521f8
+kea-dhcp-ddns.service: kea-dhcp-ddns.service.in
1f521f8
+	$(top_builddir)/tools/path_replacer.sh $< $@
1f521f8
+
1f521f8
+install-empty:
1f521f8
+
1f521f8
+install-config-files:
1f521f8
 	$(mkinstalldirs) $(DESTDIR)/@sysconfdir@/@PACKAGE@
1f521f8
 	for f in $(CONFIGFILES) ; do	\
1f521f8
 		if test -f $(DESTDIR)$(sysconfdir)/@PACKAGE@/$$f && \
1f521f8
@@ -72,4 +99,12 @@ install-data-local:
1f521f8
 		fi; \
1f521f8
 	done
1f521f8
 
1f521f8
-endif
1f521f8
+install-systemd-files:
1f521f8
+	$(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNITDIR)
1f521f8
+	$(INSTALL_DATA) kea-dhcp4.service $(DESTDIR)$(SYSTEMD_UNITDIR)/kea-dhcp4.service
1f521f8
+	$(INSTALL_DATA) kea-dhcp6.service $(DESTDIR)$(SYSTEMD_UNITDIR)/kea-dhcp6.service
1f521f8
+	$(INSTALL_DATA) kea-dhcp-ddns.service $(DESTDIR)$(SYSTEMD_UNITDIR)/kea-dhcp-ddns.service
1f521f8
+
1f521f8
+install-data-local:  $(INSTALL_TARGETS)
1f521f8
+
1f521f8
+uninstall-local: $(UNINSTALL_TARGETS)