]> git.pld-linux.org Git - packages/openvpn.git/commitdiff
- added systemd support via service generator auto/th/openvpn-2.3.2-2
authorJan Rękorajski <baggins@pld-linux.org>
Sun, 29 Dec 2013 17:57:03 +0000 (18:57 +0100)
committerJan Rękorajski <baggins@pld-linux.org>
Sun, 29 Dec 2013 17:57:03 +0000 (18:57 +0100)
- rel 2

openvpn-service-generator [new file with mode: 0644]
openvpn.spec
openvpn.sysconfig
openvpn.target [new file with mode: 0644]
openvpn@.service [new file with mode: 0644]

diff --git a/openvpn-service-generator b/openvpn-service-generator
new file mode 100644 (file)
index 0000000..5c05da1
--- /dev/null
@@ -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@.service \
+               $destunitdir/openvpn.target.wants/openvpn@$tun.service
+done
index 32498be3fb75b4c7e8ee9ed88d64daa251b3049b..a1e5018c24fc0f2e2f027ffeb896f2eb556e244a 100644 (file)
@@ -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@.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@.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
index 42a47294366466bc50aaed29fc0b0a79a1ce37d4..4fb33e62a19b821c77bf94a4e7ffd97a4eeaf13a 100644 (file)
@@ -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@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 (file)
index 0000000..652626e
--- /dev/null
@@ -0,0 +1,7 @@
+[Unit]
+Description=Start openvpn tunnels
+After=network.target
+Wants=network.target
+
+[Install]
+WantedBy=multi-user.target
diff --git a/openvpn@.service b/openvpn@.service
new file mode 100644 (file)
index 0000000..4a2db14
--- /dev/null
@@ -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
This page took 0.173297 seconds and 4 git commands to generate.