Add support for systemd.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 19 Feb 2015 20:29:46 +0000 (21:29 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Mon, 2 Mar 2015 19:56:20 +0000 (20:56 +0100)
This commit adds an optional support for systemd and contains
a service file to execute the client and a systemd timer file for
a periodic execution.

Fixes #10698.

Makefile.am
configure.ac
src/systemd/ddns.service.in [new file with mode: 0644]
src/systemd/ddns.timer [new file with mode: 0644]

index a783064..7201a93 100644 (file)
@@ -37,6 +37,7 @@ configsdir = $(sysconfdir)/ddns
 CLEANFILES =
 DISTCLEANFILES =
 EXTRA_DIST =
+INSTALL_DIRS =
 noinst_DATA =
 
 @INTLTOOL_POLICY_RULE@
@@ -45,6 +46,9 @@ noinst_DATA =
 update-po:
        $(MAKE) -C po update-po
 
+DISTCHECK_CONFIGURE_FLAGS = \
+       --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
+
 # ------------------------------------------------------------------------------
 
 AM_V_XSLT   = $(AM_V_XSLT_$(V))
@@ -135,10 +139,29 @@ endif
 
 # ------------------------------------------------------------------------------
 
+if HAVE_SYSTEMD
+systemdsystemunit_DATA = \
+       src/systemd/ddns.service \
+       src/systemd/ddns.timer
+
+CLEANFILES += \
+       $(systemdsystemunit_DATA)
+
+INSTALL_DIRS += \
+       $(systemdsystemunitdir)
+endif
+
+EXTRA_DIST += \
+       src/systemd/ddns.service.in \
+       src/systemd/ddns.timer
+
+# ------------------------------------------------------------------------------
+
 substitutions = \
        '|PACKAGE_NAME=$(PACKAGE_NAME)|' \
        '|PACKAGE_VERSION=$(PACKAGE_VERSION)|' \
-       '|configsdir=$(configsdir)|'
+       '|configsdir=$(configsdir)|' \
+       '|bindir=$(bindir)|'
 
 SED_PROCESS = \
        $(AM_V_GEN)$(MKDIR_P) $(dir $@) && \
@@ -147,3 +170,6 @@ SED_PROCESS = \
 
 ddns: ddns.in Makefile
        $(SED_PROCESS)
+
+src/systemd/%: src/systemd/%.in Makefile
+       $(SED_PROCESS)
index c036a07..66d5db3 100644 (file)
@@ -58,6 +58,11 @@ AM_PATH_PYTHON([2.7])
 
 save_LIBS="$LIBS"
 
+# pkg-config
+PKG_PROG_PKG_CONFIG
+# This makes sure pkg.m4 is available.
+m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config])
+
 # ------------------------------------------------------------------------------
 have_manpages=no
 AC_ARG_ENABLE(manpages, AS_HELP_STRING([--disable-man-pages],
@@ -67,6 +72,40 @@ AM_CONDITIONAL(ENABLE_MANPAGES, [test "x$have_manpages" = "xyes"])
 
 # ------------------------------------------------------------------------------
 
+AC_ARG_WITH([systemd],
+       AS_HELP_STRING([--with-systemd], [Enable systemd support.])
+)
+
+AS_IF([test "x$with_systemd" != "xno"],
+      [PKG_CHECK_MODULES(systemd, [libsystemd-daemon],
+      [have_systemd=yes], [have_systemd=no])],
+      [have_systemd=no]
+)
+
+AS_IF([test "x$have_systemd" = "xyes"],
+      [AC_MSG_CHECKING([for systemd system unit directory])
+       AC_ARG_WITH([systemdsystemunitdir],
+               AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
+               [], [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)]
+       )
+
+       AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
+
+       if test -n "$systemdsystemunitdir" -a "x$systemdsystemunitdir" != xno; then
+               AC_MSG_RESULT([$systemdsystemunitdir])
+       else
+               AC_MSG_ERROR([not found (try --with-systemdsystemunitdir)])
+       fi
+      ],
+      [AS_IF([test "x$with_systemd" = "xyes"],
+             [AC_MSG_ERROR([Systemd support is enabled but no systemd has been found.])
+      ])
+])
+
+AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$have_systemd" = "xyes"])
+
+# ------------------------------------------------------------------------------
+
 AC_CONFIG_FILES([
        Makefile
        po/Makefile.in
@@ -77,8 +116,9 @@ AC_OUTPUT
 AC_MSG_RESULT([
        ${PACKAGE_NAME} ${VERSION}
 
-       prefix            : ${prefix}
-       sysconfdir        : ${sysconfdir}
+       prefix:                 ${prefix}
+       sysconfdir:             ${sysconfdir}
 
-       Generate man-pages : ${have_manpages}
+       Systemd support         ${have_systemd}
+       Generate man-pages:     ${have_manpages}
 ])
diff --git a/src/systemd/ddns.service.in b/src/systemd/ddns.service.in
new file mode 100644 (file)
index 0000000..26a91c9
--- /dev/null
@@ -0,0 +1,8 @@
+[Unit]
+Description=Dynamic DNS update client
+After=network-online.target
+Requires=network-online.target
+Wants=network-online.target
+
+[Service]
+ExecStart=@bindir@/ddns update-all
diff --git a/src/systemd/ddns.timer b/src/systemd/ddns.timer
new file mode 100644 (file)
index 0000000..409c7e7
--- /dev/null
@@ -0,0 +1,9 @@
+[Unit]
+Description=Periodly execution of the Dynamic DNS update client.
+
+[Timer]
+OnActiveSec=10min
+OnUnitInactiveSec=10min
+
+[Install]
+WantedBy=multi-user.target