From 0cf6f247be7dcc93025a9db0e489677f8166d8a0 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Thu, 5 Aug 2021 10:21:28 -0700 Subject: [PATCH] Add systemd unit file to start X52 daemon --- INSTALL.md | 18 ++++++++++++++++++ configure.ac | 25 +++++++++++++++++++++++-- daemon/Makefile.am | 10 ++++++++++ daemon/x52d.service.in | 7 +++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 daemon/x52d.service.in diff --git a/INSTALL.md b/INSTALL.md index b9b5296..fdaa485 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -77,3 +77,21 @@ the following argument to `configure`: ``` --with-input-group=group ``` + +### Systemd support + +The X52 daemon can run either as a foreground process, or it can daemonize +itself to run in the background. Typical deployments with systemd will have it +run in the foreground, and disable timestamps in the logs, since those are +inserted automatically by journald. + +Systemd support is enabled by default, but can be disabled with the +`--disable-systemd` argument to `configure` + +It is also possible to configure the directory in which the service file is +installed with the following option. This is ignored if you have specified +`--disable-systemd`. + +``` +--with-systemdsystemunitdir=/path/to/systemd/system +``` diff --git a/configure.ac b/configure.ac index 2c5c170..b091baa 100644 --- a/configure.ac +++ b/configure.ac @@ -11,6 +11,7 @@ AC_REQUIRE_AUX_FILE([tap-driver.sh]) AC_PROG_CC AC_PROG_CC_STDC AC_PROG_AWK +AC_PROG_SED AM_PROG_AR AM_PATH_PYTHON([3.5]) LT_INIT @@ -51,9 +52,29 @@ PKG_CHECK_MODULES([INIH], [inih], [], AC_SEARCH_LIBS([ini_parse], [inih]) ]) -# Pinelog configuration -AC_SUBST([PINELOG_CFLAGS], ["-DPINELOG_SHOW_DATE=1 -DPINELOG_SHOW_LEVEL=1 -DPINELOG_SHOW_BACKTRACE=1"]) +# systemd support +PKG_CHECK_MODULES([SYSTEMD], [systemd], [have_systemd=yes], [have_systemd=no]) +AC_ARG_ENABLE([systemd], + [AS_HELP_STRING([--disable-systemd], [Disable systemd support])] +) +AC_ARG_WITH([systemdsystemunitdir], + [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd unit files])], + [systemdsystemunitdir=$withval], + [systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)] +) +AC_SUBST([systemdsystemunitdir], [$systemdsystemunitdir]) +AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$have_systemd" = "xyes" -a "x$enable_systemd" != "xno"]) +AM_COND_IF([HAVE_SYSTEMD],, + [ + AC_MSG_NOTICE([systemd not found or disabled. Enabling timestamps in logs]) + AX_APPEND_FLAG([-DPINELOG_SHOW_DATE=1], [PINELOG_CFLAGS]) + ] +) +# Pinelog configuration +AX_APPEND_FLAG([-DPINELOG_SHOW_LEVEL=1], [PINELOG_CFLAGS]) +AX_APPEND_FLAG([-DPINELOG_SHOW_BACKTRACE=1], [PINELOG_CFLAGS]) +AC_SUBST([PINELOG_CFLAGS]) # Check for hidapi. This uses a different pkg-config file on Linux vs other # hosts, so check accordingly diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 0c67ef0..557e01c 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -37,9 +37,19 @@ x52dconf_DATA = daemon/x52d.conf EXTRA_DIST += \ daemon/daemon.dox \ + daemon/x52d.service.in \ daemon/x52d_clock.h \ daemon/x52d_config.def \ daemon/x52d_config.h \ daemon/x52d_const.h \ daemon/x52d_device.h \ daemon/x52d.conf + +if HAVE_SYSTEMD +if !IS_MAKE_DISTCHECK +SED_ARGS = s,%bindir%,$(bindir),g +x52d.service: daemon/x52d.service.in + $(AM_V_GEN) $(SED) -e '$(SED_ARGS)' $< > $@ +systemdsystemunit_DATA = x52d.service +endif +endif diff --git a/daemon/x52d.service.in b/daemon/x52d.service.in new file mode 100644 index 0000000..39e5e48 --- /dev/null +++ b/daemon/x52d.service.in @@ -0,0 +1,7 @@ +[Unit] +Description=X52 driver daemon + +[Service] +Type=simple +ExecStart=%bindir%/x52d -f +ExecReload=kill -HUP $MAINPID