Make systemd service file handling identical to tinc 1.1.
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 6 Jan 2018 15:58:54 +0000 (16:58 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 6 Jan 2018 15:58:54 +0000 (16:58 +0100)
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
distro/Makefile.am
distro/tinc.service.in [moved from distro/tinc.service with 64% similarity]
distro/tinc@.service [deleted file]
distro/tinc@.service.in [new file with mode: 0644]

index 85e51e9..ff57755 100644 (file)
@@ -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
 
index 286c7b7..dac2b73 100644 (file)
@@ -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 > $@
similarity index 64%
rename from distro/tinc.service
rename to distro/tinc.service.in
index 1f015f0..b671042 100644 (file)
@@ -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 (file)
index 5869442..0000000
+++ /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 (file)
index 0000000..8fbf551
--- /dev/null
@@ -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