[packages/openvpn] - added systemd support via service generator - rel 2

baggins baggins at pld-linux.org
Sun Dec 29 18:57:43 CET 2013


commit ec6e7d04446ed655ab50996bb7d0060fc6a98572
Author: Jan Rękorajski <baggins at pld-linux.org>
Date:   Sun Dec 29 18:57:03 2013 +0100

    - added systemd support via service generator
    - rel 2

 openvpn-service-generator | 21 +++++++++++++++++++++
 openvpn.spec              | 32 +++++++++++++++++++++++++++++---
 openvpn.sysconfig         |  7 +++++++
 openvpn.target            |  7 +++++++
 openvpn at .service          | 16 ++++++++++++++++
 5 files changed, 80 insertions(+), 3 deletions(-)
---
diff --git a/openvpn.spec b/openvpn.spec
index 32498be..a1e5018 100644
--- a/openvpn.spec
+++ b/openvpn.spec
@@ -6,7 +6,7 @@ Summary:	VPN Daemon
 Summary(pl.UTF-8):	Serwer VPN
 Name:		openvpn
 Version:	2.3.2
-Release:	1
+Release:	2
 License:	GPL v2
 Group:		Networking/Daemons
 Source0:	http://swupdate.openvpn.net/community/releases/%{name}-%{version}.tar.gz
@@ -14,6 +14,9 @@ Source0:	http://swupdate.openvpn.net/community/releases/%{name}-%{version}.tar.g
 Source1:	%{name}.init
 Source2:	%{name}.sysconfig
 Source3:	%{name}.tmpfiles
+Source4:	openvpn-service-generator
+Source5:	openvpn.target
+Source6:	openvpn at .service
 Patch0:		%{name}-pam.patch
 URL:		http://www.openvpn.net/
 BuildRequires:	autoconf >= 2.59
@@ -84,14 +87,20 @@ sed -e 's,/''usr/lib/openvpn,%{_libdir}/%{name},' %{SOURCE3} > contrib/update-re
 rm -rf $RPM_BUILD_ROOT
 install -d $RPM_BUILD_ROOT{%{_sysconfdir}/openvpn,%{_sbindir},%{_mandir}/man8} \
 	$RPM_BUILD_ROOT{/etc/{rc.d/init.d,sysconfig},/var/run/openvpn,%{_includedir}} \
-	$RPM_BUILD_ROOT{%{_libdir}/%{name}/plugins,/usr/lib/tmpfiles.d}
+	$RPM_BUILD_ROOT{%{_libdir}/%{name}/plugins,%{systemdtmpfilesdir},%{systemdunitdir}} \
+	$RPM_BUILD_ROOT/lib/systemd/system-generators
 
 %{__make} install \
 	DESTDIR=$RPM_BUILD_ROOT
 
 install %{SOURCE1} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{name}
 install %{SOURCE2} $RPM_BUILD_ROOT/etc/sysconfig/%{name}
-install %{SOURCE3} $RPM_BUILD_ROOT/usr/lib/tmpfiles.d/%{name}.conf
+install %{SOURCE3} $RPM_BUILD_ROOT%{systemdtmpfilesdir}/%{name}.conf
+
+install -p %{SOURCE4} $RPM_BUILD_ROOT/lib/systemd/system-generators/openvpn-service-generator
+install -p %{SOURCE5} $RPM_BUILD_ROOT%{systemdunitdir}/openvpn.target
+install -p %{SOURCE6} $RPM_BUILD_ROOT%{systemdunitdir}/openvpn at .service
+ln -s /dev/null $RPM_BUILD_ROOT%{systemdunitdir}/openvpn.service
 
 %{__rm} $RPM_BUILD_ROOT%{_libdir}/%{name}/plugins/*.la
 
@@ -101,12 +110,25 @@ rm -rf $RPM_BUILD_ROOT
 %post
 /sbin/chkconfig --add openvpn
 %service openvpn restart "OpenVPN"
+%systemd_post openvpn.target
 
 %preun
 if [ "$1" = "0" ]; then
 	%service openvpn stop
 	/sbin/chkconfig --del openvpn
 fi
+%systemd_preun openvpn.target
+
+%postun
+%systemd_reload
+
+%triggerpostun -- openvpn < 2.3.2-2
+[ -f /etc/sysconfig/rpm ] && . /etc/sysconfig/rpm
+[ ${RPM_ENABLE_SYSTEMD_SERVICE:-yes} = no ] && exit 0
+[ "$(echo /etc/rc.d/rc[0-6].d/S[0-9][0-9]openvpn)" = "/etc/rc.d/rc[0-6].d/S[0-9][0-9]openvpn" ] && exit 0
+export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog
+/bin/systemctl --quiet enable openvpn.target || :
+exit 0
 
 %files
 %defattr(644,root,root,755)
@@ -116,6 +138,10 @@ fi
 %config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/%{name}
 %attr(755,root,root) %{_sbindir}/openvpn
 %attr(754,root,root) /etc/rc.d/init.d/%{name}
+%attr(755,root,root) /lib/systemd/system-generators/%{name}-service-generator
+%{systemdunitdir}/%{name}.service
+%{systemdunitdir}/%{name}.target
+%{systemdunitdir}/%{name}@.service
 %dir %{_libdir}/%{name}
 %dir %{_libdir}/%{name}/plugins
 %attr(755,root,root) %{_libdir}/%{name}/plugins/*.so
diff --git a/openvpn-service-generator b/openvpn-service-generator
new file mode 100644
index 0000000..5c05da1
--- /dev/null
+++ b/openvpn-service-generator
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+destunitdir=${1:-/tmp}
+
+# Do nothing if target is disabled
+[ -e /etc/systemd/system/multi-user.target.wants/openvpn.target ] || exit 0
+
+[ -f /etc/sysconfig/openvpn ] && . /etc/sysconfig/openvpn
+
+if [ -d $destunitdir/openvpn.target.wants ]; then
+	rm -f $destunitdir/openvpn.target.wants/openvpn@*.service
+else
+	mkdir -p $destunitdir/openvpn.target.wants
+fi
+
+for tun in $TUNNELS; do
+	[ -L $destunitdir/openvpn.target.wants/openvpn@$tun.service ] && \
+		continue
+	ln -s /lib/systemd/system/openvpn at .service \
+		$destunitdir/openvpn.target.wants/openvpn@$tun.service
+done
diff --git a/openvpn.sysconfig b/openvpn.sysconfig
index 42a4729..4fb33e6 100644
--- a/openvpn.sysconfig
+++ b/openvpn.sysconfig
@@ -7,5 +7,12 @@ SERVICE_RUN_NICE_LEVEL="+0"
 #OPENVPN_OPT="--script-security 2"
 
 # Tunnels to set up. For each tunnel name, there should be config file in /etc/openvpn
+#
+# On systems running systemd after updating the list below you have to
+# restart systemd to regenerate openvpn at TUNNEL.service services
+# (systemctl --system daemon-reload), stop and start openvpn.target when
+# removing elements from list or restart openvpn.target when only adding
+# elements (systemctl stop openvpn.target / systemctl restart openvpn.target).
+#
 #TUNNELS="mytunnel"
 TUNNELS=""
diff --git a/openvpn.target b/openvpn.target
new file mode 100644
index 0000000..652626e
--- /dev/null
+++ b/openvpn.target
@@ -0,0 +1,7 @@
+[Unit]
+Description=Start openvpn tunnels
+After=network.target
+Wants=network.target
+
+[Install]
+WantedBy=multi-user.target
diff --git a/openvpn at .service b/openvpn at .service
new file mode 100644
index 0000000..4a2db14
--- /dev/null
+++ b/openvpn at .service
@@ -0,0 +1,16 @@
+[Unit]
+Description=OpenVPN tunnel on %I
+Requires=openvpn.target
+After=openvpn.target
+PropagateReloadFrom=openvpn.target
+
+[Service]
+Type=forking
+PrivateTmp=true
+EnvironmentFile=-/etc/sysconfig/openvpn
+PIDFile=/var/run/openvpn/%i.pid
+ExecStart=/usr/sbin/openvpn --daemon --writepid /var/run/openvpn/%i.pid --config /etc/openvpn/%i.conf --cd /etc/openvpn $OPENVPN_OPT
+ExecReload=/bin/kill -HUP $MAINPID
+
+[Install]
+WantedBy=openvpn.target
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/openvpn.git/commitdiff/ec6e7d04446ed655ab50996bb7d0060fc6a98572



More information about the pld-cvs-commit mailing list