From ae6ca315165fd9fb785c3bd70337b97401ea0c15 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 12 Dec 2018 19:53:27 +0100 Subject: [PATCH] Install systemd services with autotools Change-Id: Ic4875b74bcf2b6232d915070b77fc202a03ef997 --- Makefile.am | 5 ++++- configure.ac | 19 +++++++++++++++++++ contrib/Makefile.am | 1 + contrib/systemd/Makefile.am | 6 ++++++ contrib/systemd/osmo-sysmon.service | 11 +++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 contrib/Makefile.am create mode 100644 contrib/systemd/Makefile.am create mode 100644 contrib/systemd/osmo-sysmon.service diff --git a/Makefile.am b/Makefile.am index a838715..6018753 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,6 @@ -SUBDIRS = doc src +SUBDIRS = contrib doc src ACLOCAL_AMFLAGS = -I m4 + +AM_DISTCHECK_CONFIGURE_FLAGS = \ + --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) diff --git a/configure.ac b/configure.ac index 734ac99..ba44f98 100644 --- a/configure.ac +++ b/configure.ac @@ -120,6 +120,23 @@ then CPPFLAGS="$CPPFLAGS -pg" fi +# https://www.freedesktop.org/software/systemd/man/daemon.html +PKG_PROG_PKG_CONFIG +AC_ARG_WITH([systemdsystemunitdir], + [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],, + [with_systemdsystemunitdir=auto]) +AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [ + def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd) + + AS_IF([test "x$def_systemdsystemunitdir" = "x"], + [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"], + [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])]) + with_systemdsystemunitdir=no], + [with_systemdsystemunitdir="$def_systemdsystemunitdir"])]) +AS_IF([test "x$with_systemdsystemunitdir" != "xno"], + [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])]) +AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"]) + AC_MSG_RESULT([CFLAGS="$CFLAGS"]) AC_MSG_RESULT([CPPFLAGS="$CPPFLAGS"]) @@ -127,6 +144,8 @@ dnl Generate the output AM_CONFIG_HEADER(config.h) AC_OUTPUT( + contrib/Makefile + contrib/systemd/Makefile doc/Makefile doc/examples/Makefile src/Makefile diff --git a/contrib/Makefile.am b/contrib/Makefile.am new file mode 100644 index 0000000..3439c97 --- /dev/null +++ b/contrib/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = systemd diff --git a/contrib/systemd/Makefile.am b/contrib/systemd/Makefile.am new file mode 100644 index 0000000..10b28d9 --- /dev/null +++ b/contrib/systemd/Makefile.am @@ -0,0 +1,6 @@ +EXTRA_DIST = osmo-sysmon.service + +if HAVE_SYSTEMD +systemdsystemunit_DATA = \ + osmo-sysmon.service +endif diff --git a/contrib/systemd/osmo-sysmon.service b/contrib/systemd/osmo-sysmon.service new file mode 100644 index 0000000..50d6639 --- /dev/null +++ b/contrib/systemd/osmo-sysmon.service @@ -0,0 +1,11 @@ +[Unit] +Description=Osmocom System Monitoring daemon + +[Service] +Type=simple +Restart=always +ExecStart=/usr/bin/osmo-sysmon -c /etc/osmocom/osmo-sysmon.cfg +RestartSec=2 + +[Install] +WantedBy=multi-user.target