Package: openvpn
Severity: wishlist
Version: 2.1~rc9-3
Tags: patch
User: [EMAIL PROTECTED]
Usertags: origin-ubuntu ubuntu-patch intrepid

The init script for openvpn is missing a "status" action. It is a little
complex because the init script can start zero-to-many VPNs based on
configuration.

The proposed implementation is to have the status action list the VPNs
available and their specific status, then consider it a global success
when all VPNs that should be autostarted are running, and failure
otherwise. If no VPN is configured, then it should be considered a failure.

See proposed patch to init script.
Hopes this helps !

-- 
Thierry Carrez

diff -ruN openvpn-2.1~rc9.orig/debian/control openvpn-2.1~rc9/debian/control
--- openvpn-2.1~rc9.orig/debian/control	2008-09-10 15:07:19.000000000 +0200
+++ openvpn-2.1~rc9/debian/control	2008-09-10 15:07:08.000000000 +0200
@@ -7,7 +7,7 @@
 
 Package: openvpn
 Architecture: any
-Depends: debconf | debconf-2.0, ${shlibs:Depends}, libssl0.9.8 (>= 0.9.8g-9), openssl-blacklist (>= 0.4), openvpn-blacklist
+Depends: debconf | debconf-2.0, ${shlibs:Depends}, libssl0.9.8 (>= 0.9.8g-9), openssl-blacklist (>= 0.4), openvpn-blacklist, lsb-base (>= 3.2-14)
 Recommends: net-tools
 Suggests: openssl, resolvconf
 Description: virtual private network daemon
diff -ruN openvpn-2.1~rc9.orig/debian/openvpn.init.d openvpn-2.1~rc9/debian/openvpn.init.d
--- openvpn-2.1~rc9.orig/debian/openvpn.init.d	2008-09-10 15:07:19.000000000 +0200
+++ openvpn-2.1~rc9/debian/openvpn.init.d	2008-09-10 15:05:41.000000000 +0200
@@ -189,8 +189,70 @@
   done
   log_end_msg 0
   ;;
+status)
+  GLOBAL_STATUS=0
+  if test -z "$2" ; then
+    # We want status for all defined VPNs.
+    # Returns success if all autostarted VPNs are defined and running
+    if test "x$AUTOSTART" = "xnone" ; then
+      # Consider it a failure if AUTOSTART=none
+      log_warning_msg "No VPN autostarted"
+      GLOBAL_STATUS=1
+    else
+      if ! test -z "$AUTOSTART" -o "x$AUTOSTART" = "xall" ; then
+        # Consider it a failure if one of the autostarted VPN is not defined
+        for VPN in $AUTOSTART ; do
+          if ! test -f $CONFIG_DIR/$VPN.conf ; then
+            log_warning_msg "VPN '$VPN' is in AUTOSTART but is not defined"
+            GLOBAL_STATUS=1
+          fi
+        done
+      fi
+    fi
+    for CONFIG in `cd $CONFIG_DIR; ls *.conf 2> /dev/null`; do
+      NAME=${CONFIG%%.conf}
+      # Is it an autostarted VPN ?
+      if test -z "$AUTOSTART" -o "x$AUTOSTART" = "xall" ; then
+        AUTOVPN=1
+      else
+        if test "x$AUTOSTART" = "xnone" ; then
+          AUTOVPN=0
+        else
+          AUTOVPN=0
+          for VPN in $AUTOSTART; do
+            if test "x$VPN" = "x$NAME" ; then
+              AUTOVPN=1
+            fi
+          done
+        fi
+      fi
+      if test "x$AUTOVPN" = "x1" ; then
+        # If it is autostarted, then it contributes to global status
+        status_of_proc -p /var/run/openvpn.${NAME}.pid openvpn "VPN '${NAME}'" || GLOBAL_STATUS=1
+      else
+        status_of_proc -p /var/run/openvpn.${NAME}.pid openvpn "VPN '${NAME}' (non autostarted)" || true
+      fi
+    done
+  else
+    # We just want status for specified VPNs.
+    # Returns success if all specified VPNs are defined and running
+    while shift ; do
+      [ -z "$1" ] && break
+      NAME=$1
+      if test -e $CONFIG_DIR/$NAME.conf ; then
+        # Config exists
+        status_of_proc -p /var/run/openvpn.${NAME}.pid openvpn "VPN '${NAME}'" || GLOBAL_STATUS=1
+      else
+        # Config does not exist
+        log_warning_msg "VPN '$NAME': missing $CONFIG_DIR/$NAME.conf file !"
+        GLOBAL_STATUS=1
+      fi
+    done
+  fi
+  exit $GLOBAL_STATUS
+  ;;
 *)
-  echo "Usage: $0 {start|stop|reload|restart|force-reload|cond-restart}" >&2
+  echo "Usage: $0 {start|stop|reload|restart|force-reload|cond-restart|status}" >&2
   exit 1
   ;;
 esac

Reply via email to