Optionally install systemd service files.
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 24 Sep 2015 19:53:49 +0000 (21:53 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 24 Sep 2015 20:11:16 +0000 (22:11 +0200)
If --with-systemd is given when running the configure script, two
systemd service files will be installed. There is a template
tinc@.service, which can be used to control individual instances of
tinc. For example:

systemctl enable tinc@foo

Will create an instance for tinc with netname foo. There is also a
tinc.service, which can be used to start and stop all instances at once.

Makefile.am
configure.ac
systemd/Makefile.am [new file with mode: 0644]
systemd/tinc.service [new file with mode: 0644]
systemd/tinc@.service [new file with mode: 0644]

index c0014d5..177f549 100644 (file)
@@ -2,7 +2,7 @@
 
 AUTOMAKE_OPTIONS = gnu
 
-SUBDIRS =  src doc gui test
+SUBDIRS =  src doc gui test systemd
 
 ACLOCAL_AMFLAGS = -I m4
 
index 04f16bf..e6fd3b0 100644 (file)
@@ -115,6 +115,17 @@ AC_ARG_WITH(windows2000,
   ]
 )
 
+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="/lib/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)
 AM_CONDITIONAL(SOLARIS, test "$solaris" = true)
@@ -123,6 +134,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
 
@@ -250,6 +262,6 @@ AC_ARG_ENABLE(jumbograms,
   ]
 )
 
-AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile gui/Makefile test/Makefile])
+AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile gui/Makefile test/Makefile systemd/Makefile])
 
 AC_OUTPUT
diff --git a/systemd/Makefile.am b/systemd/Makefile.am
new file mode 100644 (file)
index 0000000..a1bfe12
--- /dev/null
@@ -0,0 +1,4 @@
+if WITH_SYSTEMD
+systemddir = @systemd_path@
+dist_systemd_DATA = tinc.service tinc@.service
+endif
diff --git a/systemd/tinc.service b/systemd/tinc.service
new file mode 100644 (file)
index 0000000..d911fa7
--- /dev/null
@@ -0,0 +1,20 @@
+# This is a mostly empty service, but allows commands like stop, start, reload
+# to propagate to all tinc@ service instances.
+
+[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
+
+[Install]
+WantedBy=multi-user.target
diff --git a/systemd/tinc@.service b/systemd/tinc@.service
new file mode 100644 (file)
index 0000000..78ef25b
--- /dev/null
@@ -0,0 +1,19 @@
+[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=/etc/tinc/%i
+ExecStart=/usr/sbin/tincd -n %i -D
+ExecReload=/usr/sbin/tinc -n %i reload
+Restart=on-failure
+RestartSec=5
+TimeoutStopSec=5
+
+[Install]
+WantedBy=tinc.service