From a563e6dd8c88865351c05ebc72de86dac7a839d5 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 6 Jan 2018 16:58:54 +0100 Subject: [PATCH] Make systemd service file handling identical to tinc 1.1. This removes hardcoded paths from systemd unit files, and sets the default systemd unit path to ${libdir}/systemd/system. The configure option is now renamed to --with-systemd[=PATH]. These changes now also ensure that make distcheck runs without any errors. Closes #160 on GitHub. --- configure.ac | 27 ++++++++++-------------- distro/Makefile.am | 25 +++++++++++++++------- distro/{tinc.service => tinc.service.in} | 6 +++++- distro/tinc@.service | 17 --------------- distro/tinc@.service.in | 20 ++++++++++++++++++ 5 files changed, 53 insertions(+), 42 deletions(-) rename distro/{tinc.service => tinc.service.in} (64%) delete mode 100644 distro/tinc@.service create mode 100644 distro/tinc@.service.in diff --git a/configure.ac b/configure.ac index 85e51e98..ff577553 100644 --- a/configure.ac +++ b/configure.ac @@ -21,8 +21,6 @@ AC_PROG_INSTALL AM_PROG_CC_C_O -PKG_PROG_PKG_CONFIG - dnl Check and set OS AC_CANONICAL_HOST @@ -116,20 +114,16 @@ AC_ARG_WITH(windows2000, ] ) -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_ARG_WITH(systemd, + AS_HELP_STRING([--with-systemd@<:@=DIR@:>@], [install systemd service files @<:@to DIR if specified@:>@]), + [ systemd=true; systemd_path="$with_systemd" ], + [ systemd=false ] +) + +AS_IF([test "x$with_systemd" = "xyes"], [systemd_path="\${libdir}/systemd/system"], + [AS_IF([test "x$with_systemd" = "xno"], [systemd=false])]) + +AC_SUBST(systemd_path, $systemd_path) AM_CONDITIONAL(LINUX, test "$linux" = true) AM_CONDITIONAL(BSD, test "$bsd" = true) @@ -139,6 +133,7 @@ AM_CONDITIONAL(CYGWIN, test "$cygwin" = true) AM_CONDITIONAL(UML, test "$uml" = true) AM_CONDITIONAL(VDE, test "$vde" = true) AM_CONDITIONAL(TUNEMU, test "$tunemu" = true) +AM_CONDITIONAL(WITH_SYSTEMD, test "$systemd" = true) AC_CACHE_SAVE diff --git a/distro/Makefile.am b/distro/Makefile.am index 286c7b76..dac2b73d 100644 --- a/distro/Makefile.am +++ b/distro/Makefile.am @@ -1,9 +1,18 @@ -EXTRA_DIST = \ - tinc.service \ - tinc@.service - -if HAVE_SYSTEMD -systemdsystemunit_DATA = \ - tinc.service \ - tinc@.service +EXTRA_DIST = tinc.service.in tinc@.service.in + +CLEANFILES = tinc.service tinc@.service + +if WITH_SYSTEMD +systemddir = @systemd_path@ +nodist_systemd_DATA = tinc.service tinc@.service endif + +substitute = sed \ + -e s,'@sbindir\@',"$(sbindir)",g \ + -e s,'@sysconfdir\@',"$(sysconfdir)",g + +tinc.service: $(srcdir)/tinc.service.in + $(AM_V_GEN)$(substitute) $(srcdir)/tinc.service.in > $@ + +tinc@.service: $(srcdir)/tinc@.service.in + $(AM_V_GEN)$(substitute) $(srcdir)/tinc@.service.in > $@ diff --git a/distro/tinc.service b/distro/tinc.service.in similarity index 64% rename from distro/tinc.service rename to distro/tinc.service.in index 1f015f0b..b6710424 100644 --- a/distro/tinc.service +++ b/distro/tinc.service.in @@ -3,14 +3,18 @@ [Unit] Description=Tinc VPN +Documentation=info:tinc +Documentation=man:tinc(8) man:tinc.conf(5) +Documentation=http://tinc-vpn.org/docs/ After=network.target +Wants=network.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/true ExecReload=/bin/true -WorkingDirectory=/etc/tinc +WorkingDirectory=@sysconfdir@/tinc [Install] WantedBy=multi-user.target diff --git a/distro/tinc@.service b/distro/tinc@.service deleted file mode 100644 index 58694429..00000000 --- a/distro/tinc@.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Tinc net %i -PartOf=tinc.service -ReloadPropagatedFrom=tinc.service - -[Service] -Type=simple -WorkingDirectory=/etc/tinc/%i -ExecStart=/usr/sbin/tincd -n %i -D -ExecReload=/usr/sbin/tincd -n %i -kHUP -KillMode=mixed -TimeoutStopSec=5 -Restart=always -RestartSec=60 - -[Install] -WantedBy=tinc.service diff --git a/distro/tinc@.service.in b/distro/tinc@.service.in new file mode 100644 index 00000000..8fbf551f --- /dev/null +++ b/distro/tinc@.service.in @@ -0,0 +1,20 @@ +[Unit] +Description=Tinc net %i +Documentation=info:tinc +Documentation=man:tinc(8) man:tinc.conf(5) +Documentation=http://tinc-vpn.org/docs/ +PartOf=tinc.service +ReloadPropagatedFrom=tinc.service + +[Service] +Type=simple +WorkingDirectory=@sysconfdir@/tinc/%i +ExecStart=@sbindir@/tincd -n %i -D +ExecReload=@sbindir@/tincd -n %i -kHUP +KillMode=mixed +Restart=on-failure +RestartSec=5 +TimeoutStopSec=5 + +[Install] +WantedBy=tinc.service -- 2.20.1