From 7efb435d8ece6ead568db61692566ad5dc59ea623f2f85c1e8f412a8f46e2464 Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Thu, 20 Sep 2012 10:52:54 +0000 Subject: [PATCH 1/2] - Fixed openvpn init script to not map reopen to reload so the reopen code is without any effect (bnc#781106). - Added requested OPENVPN_AUTOSTART variable allowing to provide an optional list of config names started by default (bnc#692440). OBS-URL: https://build.opensuse.org/package/show/network:vpn/openvpn?expand=0&rev=43 --- openvpn.changes | 8 ++++++++ openvpn.init | 41 ++++++++++++++++++++++++++++++++++------- openvpn.spec | 7 ++++++- openvpn.sysconfig | 16 ++++++++++++++++ 4 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 openvpn.sysconfig diff --git a/openvpn.changes b/openvpn.changes index 1e4bee1..75a386d 100644 --- a/openvpn.changes +++ b/openvpn.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Thu Sep 20 10:50:23 UTC 2012 - mt@suse.com + +- Fixed openvpn init script to not map reopen to reload so the + reopen code is without any effect (bnc#781106). +- Added requested OPENVPN_AUTOSTART variable allowing to provide + an optional list of config names started by default (bnc#692440). + ------------------------------------------------------------------- Wed Aug 22 14:50:39 UTC 2012 - cfarrell@suse.com diff --git a/openvpn.init b/openvpn.init index a9c3774..bb63df8 100644 --- a/openvpn.init +++ b/openvpn.init @@ -24,9 +24,8 @@ # Description: Start OpenVPN tunnel ### END INIT INFO -# we don't use any... -# test -s /etc/sysconfig/openvpn && \ -# . /etc/sysconfig/openvpn +test -s /etc/sysconfig/openvpn && \ + . /etc/sysconfig/openvpn DAEMON="OpenVPN" openvpn=/usr/sbin/openvpn @@ -73,6 +72,16 @@ shopt -s nullglob action="$1" ; shift config="$1" ; shift +autostart_filter() +{ + test "x$config" != "x" && return 0 + test "x$OPENVPN_AUTOSTART" = "x" && return 0 + for n in ${OPENVPN_AUTOSTART} ; do + test "x$n" = "x$1" && return 0 + done + return 1 +} + case "$action" in start) /sbin/modprobe tun &>/dev/null @@ -81,6 +90,7 @@ case "$action" in for conf in $confdir/${config:-*}.conf ; do test -f "$conf" || continue name=$(basename "${conf%%.conf}") + autostart_filter "$name" || continue pidfile="$piddir/${name}.pid" echo -n "Starting $DAEMON [$name] " @@ -164,14 +174,30 @@ case "$action" in restart) ## Stop the service and regardless of whether it was ## running or not, start it again. - $0 stop ${config:+"$config"} - sleep 3 - $0 start ${config:+"$config"} + # When nothing is running, start specified config or + # the defult (autostart) set. Otherwise we stop the + # specified one or all that are currently running. + # Then start specified one or all that were running + # before and have a config. Makes sense? :-) + name="" + list=($config) + for pidfile in $piddir/${config:-*}.pid; do + test -f "$pidfile" || continue + name=$(basename "${pidfile%%.pid}") + $0 stop "$name" + rc_status + test "x$name" = "x$config" && continue # in list + test -f "$confdir/${name}.conf" && list+=("$name") + done + + test "x$name" = x || sleep 3 # for what was this needed? + + $0 start "${list[@]}" # Remember status and be quiet rc_status ;; - reopen|reload|force-reload) + reload|force-reload) for pidfile in $piddir/${config:-*}.pid; do test -f "$pidfile" || continue name=$(basename "${pidfile%%.pid}") @@ -219,6 +245,7 @@ case "$action" in for conf in $confdir/${config:-*}.conf ; do test -f "$conf" || continue name=$(basename "${conf%%.conf}") + autostart_filter "$name" || continue pidfile="$piddir/${name}.pid" if test ! -f "$pidfile" ; then diff --git a/openvpn.spec b/openvpn.spec index ec3ad91..f31fd0f 100644 --- a/openvpn.spec +++ b/openvpn.spec @@ -194,12 +194,16 @@ for pi in auth-pam down-root; do done # we install docs via spec into _defaultdocdir/name/management-notes.txt rm -rf $RPM_BUILD_ROOT%{_datadir}/doc/{OpenVPN,%name} +# the /etc/sysconfig/openvpn template +install -d -m0755 %{buildroot}/var/adm/fillup-templates +install -m0600 $RPM_SOURCE_DIR/openvpn.sysconfig \ + %{buildroot}/var/adm/fillup-templates/sysconfig.openvpn %clean if ! test -f /.buildenv; then rm -rf $RPM_BUILD_ROOT; fi %post -%{?fillup_and_insserv:%fillup_and_insserv -f} +%{?fillup_and_insserv:%fillup_and_insserv} %preun %{?stop_on_removal:%stop_on_removal openvpn} @@ -228,6 +232,7 @@ if ! test -f /.buildenv; then rm -rf $RPM_BUILD_ROOT; fi %dir %{_libdir}/%{name} %dir %{plugin_dir} %dir %{plugin_libdir} +/var/adm/fillup-templates/sysconfig.openvpn %files down-root-plugin %defattr(-,root,root) diff --git a/openvpn.sysconfig b/openvpn.sysconfig new file mode 100644 index 0000000..e29391d --- /dev/null +++ b/openvpn.sysconfig @@ -0,0 +1,16 @@ +## Type: list("",) +## Default: "" +# +# Allows to specify an optional white-list of config names to start +# in /etc/init.d/openvpn. +# +# Unlisted config names can be still started using the explicit name, +# e.g. "/etc/init.d/openvpn start tun0" will start openvpn for the +# "/etc/openvpn/tun0.conf" config file. +# +# Setting the variable to e.g. "foo bar" will cause the start of the +# "/etc/openvpn/foo.conf" and "/etc/openvpn/bar.conf" config files. +# When empty, the init script will start all existing config files. +# +OPENVPN_AUTOSTART="" + From a1addb0f77abc16898a68cba1d1dda8ee1e2177ffc5a5bdd0441c10ec4364b04 Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Thu, 20 Sep 2012 10:53:37 +0000 Subject: [PATCH 2/2] Ahm... forgot to add openvpn.sysconfig to the list OBS-URL: https://build.opensuse.org/package/show/network:vpn/openvpn?expand=0&rev=44 --- openvpn.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/openvpn.spec b/openvpn.spec index f31fd0f..8502a33 100644 --- a/openvpn.spec +++ b/openvpn.spec @@ -33,6 +33,7 @@ Source2: openvpn.init Source3: openvpn.README.SUSE Source4: client-netconfig.up Source5: client-netconfig.down +Source6: openvpn.sysconfig Patch1: %{name}-2.1-plugin-man.dif Patch2: %{name}-2.1-plugin-build.dif Patch3: openvpn-2.1-systemd-passwd.patch