From d8962ffe031c8ef74ef6af650f7dd729f6e500dceb5bdc5d0ed71ea2565eea19 Mon Sep 17 00:00:00 2001 From: OBS User unknown Date: Tue, 17 Feb 2009 21:59:41 +0000 Subject: [PATCH] OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/openvpn?expand=0&rev=11 --- openvpn.changes | 6 ++ openvpn.init | 156 ++++++++++++++++++++++++++++++++++-------------- openvpn.spec | 7 ++- 3 files changed, 121 insertions(+), 48 deletions(-) diff --git a/openvpn.changes b/openvpn.changes index 718c177..ecf5ff2 100644 --- a/openvpn.changes +++ b/openvpn.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Tue Feb 17 18:22:23 CET 2009 - mt@suse.de + +- Improved init script to show config name in action messages + and allow to specify a config name in the second argument. + ------------------------------------------------------------------- Mon Dec 1 10:58:12 CET 2008 - mt@suse.de diff --git a/openvpn.init b/openvpn.init index 132ec7a..17876c2 100644 --- a/openvpn.init +++ b/openvpn.init @@ -1,7 +1,9 @@ #! /bin/sh # Copyright (c) 2003 SuSE Linux AG +# Copyright (c) 2004-2009 SUSE LINUX Products GmbH, Nuernberg, Germany. # # Author: Peter Poeml +# Marius Tomaschewski # # inspired by the init script contributed to the OpenVPN project by # Douglas Keller @@ -22,7 +24,7 @@ # Description: Start OpenVPN tunnel ### END INIT INFO - +# we don't use any... # test -s /etc/sysconfig/openvpn && \ # . /etc/sysconfig/openvpn @@ -67,58 +69,82 @@ rc_reset # considered a success. shopt -s nullglob -ret=true -case "$1" in +action="$1" ; shift +config="$1" ; shift + +case "$action" in start) - echo -n "Starting $DAEMON " - /sbin/modprobe tun &>/dev/null - for conf in $confdir/*.conf; do - pidfile=$piddir/$(basename "${conf%%.conf}").pid - if [ -e "$pidfile" ]; then + name="" + for conf in $confdir/${config:-*}.conf ; do + test -f "$conf" || continue + name=$(basename "${conf%%.conf}") + pidfile="$piddir/${name}.pid" + + echo -n "Starting $DAEMON [$name] " + + if [ -f "$pidfile" ]; then killproc -p "$pidfile" -USR2 $openvpn - s=$? - case $s in - 0) continue ;; # no an error - 7) rm -f "$pidfile" ;; # not running - *) ret=false ; continue ;; + ret=$? + case $ret in + 7) # not running, remove pid and start + echo -n "(removed stale pid file) " ; + rm -f "$pidfile" ;; + 0) # running - no an error, skip start + rc_failed 0 ; rc_status -v ; continue ;; + *) # another error, set it and continue + rc_failed 1 ; rc_status -v ; continue ;; esac fi + # openvpn may ask for auth ... + echo "" $openvpn --daemon \ --writepid "$pidfile" \ --config "$conf" \ --cd $confdir \ - || ret=false - done + || rc_failed 1 + + # write the status one line up + rc_status -v1 + done + test -n "$name" || { + echo 1>&2 "No $DAEMON${config:+ '$config'} configuration file found" + rc_failed 6 + } + rc_status - # Remember status and be verbose - $ret - rc_status -v ;; stop) - echo -n "Shutting down $DAEMON " ## Stop daemon with killproc(8) and if this fails ## set echo the echo return value. - for i in $piddir/*.pid; do - killproc -p "$i" $openvpn || ret=false - done + name="" + for pidfile in $piddir/${config:-*}.pid; do + test -f "$pidfile" || continue + name=$(basename "${pidfile%%.pid}") - # Remember status and be verbose - $ret - rc_status -v + echo -n "Shutting down $DAEMON [$name] " + killproc -p "$pidfile" $openvpn + rc_status -v + rm -f "$pidfile" + done + test -n "$name" || { + echo 1>&2 "No $DAEMON${config:+ for '$config' configuration} running" + } + + rc_status ;; try-restart) ## Do a restart only if the service was active before. ## Note: try-restart is now part of LSB (as of 1.9). ## RH has a similar command named condrestart. - $0 status + $0 status ${config:+"$config"} if test $? = 0; then - $0 restart + $0 restart ${config:+"$config"} else rc_reset # Not running is not a failure. fi @@ -128,43 +154,81 @@ case "$1" in restart) ## Stop the service and regardless of whether it was ## running or not, start it again. - $0 stop + $0 stop ${config:+"$config"} sleep 3 - $0 start + $0 start ${config:+"$config"} # Remember status and be quiet rc_status ;; - reload|force-reload) - for i in $piddir/*.pid; do - killproc -p "$i" -HUP $openvpn || ret=false + reopen|reload|force-reload) + for pidfile in $piddir/${config:-*}.pid; do + test -f "$pidfile" || continue + name=$(basename "${pidfile%%.pid}") + + echo -n "Reload service $DAEMON [$name] " + killproc -p "$pidfile" -HUP $openvpn + rc_status -v done - rc_status -v + rc_status ;; reopen) - for i in $piddir/*.pid; do - killproc -p "$i" -USR1 $openvpn || ret=false + for pidfile in $piddir/${config:-*}.pid; do + test -f "$pidfile" || continue + name=$(basename "${pidfile%%.pid}") + + echo -n "Reopen service $DAEMON [$name] " + killproc -p "$pidfile" -USR1 $openvpn + rc_status -v done - rc_status -v + rc_status ;; status) - echo -n "Checking for $DAEMON: " - running=false - for i in $piddir/*.pid; do - running=true - killproc -p "$i" -USR2 $openvpn || { rv=$?; ret=false; } - done - if $running; then - $ret + name="" + for pidfile in $piddir/${config:-*}.pid; do + test -f "$pidfile" || continue + name=$(basename "${pidfile%%.pid}") + + echo -n "Checking for $DAEMON [$name] " + killproc -p "$pidfile" -USR2 $openvpn rc_status -v - echo Status written to /var/log/messages + done + if test -n "$name" ; then + echo "$DAEMON status written to /var/log/messages" else + echo -n "Checking for $DAEMON " rc_failed 3 rc_status -v fi ;; + probe) + ## Optional: Probe for the necessity of a reload, print out the + ## argument to this init script which is required for a reload. + ## Note: probe is not (yet) part of LSB (as of 1.9) + result="" + for conf in $confdir/${config:-*}.conf ; do + test -f "$conf" || continue + name=$(basename "${conf%%.conf}") + pidfile="$piddir/${name}.pid" + + if test ! -f "$pidfile" ; then + result="restart" + elif test "$conf" -nt "$pidfile" ; then + test "$result" = "restart" || \ + result="reload" + fi + done + for pidfile in $piddir/${config:-*}.pid; do + test -f "$pidfile" || continue + name=$(basename "${pidfile%%.pid}") + conf="$confdir/${name}.conf" + + test -f "$conf" && result="restart" + done + test -n "$result" && echo "$result" + ;; *) - echo "Usage: $0 {start|stop|status|try-restart|restart|reload|reopen}" + echo "Usage: $0 {start|stop|status|try-restart|restart|reload|reopen|probe}" exit 1 esac rc_exit diff --git a/openvpn.spec b/openvpn.spec index 0238019..6188e7c 100644 --- a/openvpn.spec +++ b/openvpn.spec @@ -1,7 +1,7 @@ # # spec file for package openvpn (Version 2.0.9) # -# Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -27,7 +27,7 @@ AutoReqProv: on PreReq: %insserv_prereq %fillup_prereq %endif Version: 2.0.9 -Release: 143 +Release: 144 Summary: Full-featured SSL VPN solution using a TUN/TAP Interface Source: http://openvpn.net/release/openvpn-%{version}.tar.gz Source1: http://openvpn.net/signatures/openvpn-%{version}.tar.gz.asc @@ -221,6 +221,9 @@ if ! test -f /.buildenv; then rm -rf $RPM_BUILD_ROOT; fi %{plugin_libdir}/openvpn-auth-pam.so %changelog +* Tue Feb 17 2009 mt@suse.de +- Improved init script to show config name in action messages + and allow to specify a config name in the second argument. * Mon Dec 01 2008 mt@suse.de - Removed restart_on_update rpm install hook that may break the update process, e.g. when openvpn asks for auth data or the