From 1f5bd7321e8029fa05f9e7f46a9a9a2e7568656f Mon Sep 17 00:00:00 2001 From: Alberto Gonzalez Iniesta Date: Fri, 12 Sep 2014 12:52:30 +0200 Subject: First works to improve systemd integration Add openvpn-generator to mimic AUTOSTART feature from SysV init script --- debian/changelog | 3 +++ debian/default | 5 +++++ debian/openvpn-generator | 40 ++++++++++++++++++++++++++++++++++++++++ debian/openvpn.install | 2 +- debian/openvpn.service | 8 +++++--- debian/openvpn@.service | 3 ++- 6 files changed, 56 insertions(+), 5 deletions(-) create mode 100755 debian/openvpn-generator diff --git a/debian/changelog b/debian/changelog index a0f266b..ff008df 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,9 @@ openvpn (2.3.4-1) unstable; urgency=medium * Upload to unstable. * New upstream release. (Closes: #752568) * Add Turkish debconf translation. (Closes: #759879) + * Replace openvpn-systemd-helper with a systemd generator. + Thanks Ondřej Surý, Ansgar Burchardt and postgresql-common for + the ideas, help and inspiration. -- Alberto Gonzalez Iniesta Tue, 02 Sep 2014 12:06:06 +0200 diff --git a/debian/default b/debian/default index d601933..0dfa6a1 100644 --- a/debian/default +++ b/debian/default @@ -7,6 +7,11 @@ # The VPN name refers to the VPN configutation file name. # i.e. "home" would be /etc/openvpn/home.conf # +# If you're running systemd, changing this variable will +# require running "systemctl daemon-reload" followed by +# a restart of the openvpn service (if you removed entries +# you may have to stop those manually) +# #AUTOSTART="all" #AUTOSTART="none" #AUTOSTART="home office" diff --git a/debian/openvpn-generator b/debian/openvpn-generator new file mode 100755 index 0000000..d6ac1aa --- /dev/null +++ b/debian/openvpn-generator @@ -0,0 +1,40 @@ +#!/bin/sh + +# This systemd generator creates dependency symlinks that make all OpenVPN +# tunnels listed in /etc/default/openvpn's AUTOSTART be started/stopped/reloaded +# when openvpn.service is started/stopped/reloaded. + +set -eu + +GENDIR="$1" +WANTDIR="$1/openvpn.service.wants" +SERVICEFILE="/lib/systemd/system/openvpn@.service" +AUTOSTART="all" +CONFIG_DIR=/etc/openvpn + +mkdir -p "$WANTDIR" + +if test -e /etc/default/openvpn ; then + . /etc/default/openvpn +fi + +# No VPNs automatically started +if test "x$AUTOSTART" = "xnone" ; then + exit 0 +fi + +if test "x$AUTOSTART" = "xall" -o -z "$AUTOSTART" ; then + for CONFIG in `cd $CONFIG_DIR; ls *.conf 2> /dev/null`; do + NAME=${CONFIG%%.conf} + ln -s "$SERVICEFILE" "$WANTDIR/openvpn@$NAME.service" + done +else + for NAME in $AUTOSTART ; do + if test -e $CONFIG_DIR/$NAME.conf ; then + ln -s "$SERVICEFILE" "$WANTDIR/openvpn@$NAME.service" + fi + done +fi + +exit 0 + diff --git a/debian/openvpn.install b/debian/openvpn.install index 3877165..b03fbb7 100644 --- a/debian/openvpn.install +++ b/debian/openvpn.install @@ -1,4 +1,4 @@ debian/openvpn@.service /lib/systemd/system debian/openvpn.conf /usr/lib/tmpfiles.d debian/openvpn.service /lib/systemd/system -debian/openvpn-systemd-helper /usr/sbin +debian/openvpn-generator /lib/systemd/system-generators diff --git a/debian/openvpn.service b/debian/openvpn.service index b76e36e..e1d49a8 100644 --- a/debian/openvpn.service +++ b/debian/openvpn.service @@ -1,3 +1,6 @@ +# This service is actually a systemd target, +# but we are using a service since targets cannot be reloaded. + [Unit] Description=OpenVPN service After=network.target @@ -5,9 +8,8 @@ After=network.target [Service] Type=oneshot RemainAfterExit=yes -ExecStart=/usr/sbin/openvpn-systemd-helper start -ExecStop=/usr/sbin/openvpn-systemd-helper stop -ExecReload=/usr/sbin/openvpn-systemd-helper reload +ExecStart=/bin/true +ExecStop=/bin/true WorkingDirectory=/etc/openvpn [Install] diff --git a/debian/openvpn@.service b/debian/openvpn@.service index a6834da..be47429 100644 --- a/debian/openvpn@.service +++ b/debian/openvpn@.service @@ -1,6 +1,7 @@ [Unit] Description=OpenVPN connection to %i -After=network.target +PartOf=openvpn.service +ReloadPropagatedFrom=openvpn.service [Service] Type=forking -- cgit v1.2.3