From db8594f6f5cd40cbf3c52e97530459b4bfcba479 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 10 Apr 2016 14:13:44 +0200 Subject: [PATCH] Add systemd service files. --- Makefile.am | 2 +- configure.ac | 19 ++++++++++++++++++- distro/Makefile.am | 5 +++++ distro/tinc.service | 16 ++++++++++++++++ distro/tinc@.service | 17 +++++++++++++++++ 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 distro/Makefile.am create mode 100644 distro/tinc.service create mode 100644 distro/tinc@.service diff --git a/Makefile.am b/Makefile.am index b09f531..c03d020 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = gnu -SUBDIRS = m4 src doc +SUBDIRS = m4 src doc distro ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 332b863..4aee2a3 100644 --- a/configure.ac +++ b/configure.ac @@ -21,6 +21,8 @@ AC_PROG_INSTALL AM_PROG_CC_C_O +PKG_PROG_PKG_CONFIG + dnl Check and set OS AC_CANONICAL_HOST @@ -114,6 +116,21 @@ 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"]) + AM_CONDITIONAL(LINUX, test "$linux" = true) AM_CONDITIONAL(BSD, test "$bsd" = true) AM_CONDITIONAL(SOLARIS, test "$solaris" = true) @@ -229,6 +246,6 @@ AC_ARG_ENABLE(jumbograms, ] ) -AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile m4/Makefile]) +AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile m4/Makefile distro/Makefile]) AC_OUTPUT diff --git a/distro/Makefile.am b/distro/Makefile.am new file mode 100644 index 0000000..4e41f3b --- /dev/null +++ b/distro/Makefile.am @@ -0,0 +1,5 @@ +if HAVE_SYSTEMD +systemdsystemunit_DATA = \ + tinc.service \ + tinc@.service +endif diff --git a/distro/tinc.service b/distro/tinc.service new file mode 100644 index 0000000..1f015f0 --- /dev/null +++ b/distro/tinc.service @@ -0,0 +1,16 @@ +# This is a mostly empty service, but allows commands like stop, start, reload +# to propagate to all tinc@ service instances. + +[Unit] +Description=Tinc VPN +After=network.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/bin/true +ExecReload=/bin/true +WorkingDirectory=/etc/tinc + +[Install] +WantedBy=multi-user.target diff --git a/distro/tinc@.service b/distro/tinc@.service new file mode 100644 index 0000000..4bb4d2d --- /dev/null +++ b/distro/tinc@.service @@ -0,0 +1,17 @@ +[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 +ExecStop=/usr/sbin/tincd -n %i -k +TimeoutStopSec=5 +Restart=always +RestartSec=60 + +[Install] +WantedBy=tinc.service -- 2.25.1