From be748fa8de5a78a056821a06b7ae61d4be22df9b Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 17 Nov 2019 14:52:24 +0000 Subject: [PATCH] Add systemd unit files for location-downloader Signed-off-by: Michael Tremer --- .gitignore | 2 ++ Makefile.am | 22 +++++++++++++ configure.ac | 37 ++++++++++++++++++++++ src/systemd/location-downloader.service.in | 7 ++++ src/systemd/location-downloader.timer.in | 9 ++++++ 5 files changed, 77 insertions(+) create mode 100644 src/systemd/location-downloader.service.in create mode 100644 src/systemd/location-downloader.timer.in diff --git a/.gitignore b/.gitignore index 19e05bd..45e2fea 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,7 @@ Makefile.in /stamp-h1 /src/python/location-downloader /src/python/location-query +/src/systemd/location-downloader.service +/src/systemd/location-downloader.timer /test.db /testdata.db diff --git a/Makefile.am b/Makefile.am index 33a7e98..859d9cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,6 @@ EXTRA_DIST = CLEANFILES = +INSTALL_DIRS = ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} AM_MAKEFLAGS = --no-print-directory @@ -36,11 +37,15 @@ LIBLOC_CURRENT=0 LIBLOC_REVISION=0 LIBLOC_AGE=0 +DISTCHECK_CONFIGURE_FLAGS = \ + --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) + SED_PROCESS = \ $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(SED) \ -e 's,@VERSION\@,$(VERSION),g' \ -e 's,@prefix\@,$(prefix),g' \ -e 's,@exec_prefix\@,$(exec_prefix),g' \ + -e 's,@bindir\@,$(bindir),g' \ -e 's,@libdir\@,$(libdir),g' \ -e 's,@includedir\@,$(includedir),g' \ -e 's,@databasedir\@,$(databasedir),g' \ @@ -220,6 +225,23 @@ EXTRA_DIST += \ CLEANFILES += \ src/python/location-downloader \ src/python/location-query +# ------------------------------------------------------------------------------ + +if HAVE_SYSTEMD +systemdsystemunit_DATA = \ + src/systemd/location-downloader.service \ + src/systemd/location-downloader.timer + +CLEANFILES += \ + $(systemdsystemunit_DATA) + +INSTALL_DIRS += \ + $(systemdsystemunitdir) +endif + +EXTRA_DIST += \ + src/systemd/location-downloader.service.in \ + src/systemd/location-downloader.timer.in # ------------------------------------------------------------------------------ diff --git a/configure.ac b/configure.ac index c4ba1f3..cd224eb 100644 --- a/configure.ac +++ b/configure.ac @@ -96,6 +96,42 @@ my_CFLAGS="\ " AC_SUBST([my_CFLAGS]) +# ------------------------------------------------------------------------------ + +AC_ARG_WITH([systemd], + AS_HELP_STRING([--with-systemd], [Enable systemd support.]) +) + +AS_IF([test "x$with_systemd" != "xno"], + [PKG_CHECK_MODULES(systemd, [libsystemd], + [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"]) + +# ------------------------------------------------------------------------------ + # Python AM_PATH_PYTHON([3.4]) PKG_CHECK_MODULES([PYTHON], [python-${PYTHON_VERSION}]) @@ -130,6 +166,7 @@ AC_MSG_RESULT([ ldflags: ${LDFLAGS} debug: ${enable_debug} + systemd support: ${have_systemd} Bindings: perl: ${enable_perl} diff --git a/src/systemd/location-downloader.service.in b/src/systemd/location-downloader.service.in new file mode 100644 index 0000000..12c9e05 --- /dev/null +++ b/src/systemd/location-downloader.service.in @@ -0,0 +1,7 @@ +[Unit] +Description=Automatic Location Database Updater +Requires=network.target + +[Service] +Type=oneshot +ExecStart=@bindir@/location-downloader update diff --git a/src/systemd/location-downloader.timer.in b/src/systemd/location-downloader.timer.in new file mode 100644 index 0000000..5e3be1a --- /dev/null +++ b/src/systemd/location-downloader.timer.in @@ -0,0 +1,9 @@ +[Unit] +Description=Update location database once a day + +[Timer] +OnCalendar=daily +RandomizedDelaySec=24h + +[Install] +WantedBy=timers.target -- 2.47.2