[Opensrf-commits] r2227 - in branches/rel_2_0: bin src/python (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Mar 30 00:34:42 EDT 2011


Author: dbs
Date: 2011-03-30 00:34:39 -0400 (Wed, 30 Mar 2011)
New Revision: 2227

Modified:
   branches/rel_2_0/bin/osrf_ctl.sh.in
   branches/rel_2_0/src/python/opensrf.py.in
Log:
Handle the common NXDOMAIN problem with Python a bit more gracefully

Rather than dumping a nasty full stacktrace to the command line, we
print a hopefully helpful pointer to the actual problem in plain
English.

Also, rather than stopping everything if a "stop_all" command was
issued, skip the error status in osrf_ctl.sh for the Python bit
and carry on shutting down the other services. A bit more convenient
if you want to have Python enabled but don't necessarily need it
running.


Modified: branches/rel_2_0/bin/osrf_ctl.sh.in
===================================================================
--- branches/rel_2_0/bin/osrf_ctl.sh.in	2011-03-30 04:31:28 UTC (rev 2226)
+++ branches/rel_2_0/bin/osrf_ctl.sh.in	2011-03-30 04:34:39 UTC (rev 2227)
@@ -197,7 +197,9 @@
     [ -e $PID_OSRF_PYTHON ] && rm $PID_OSRF_PYTHON;
     OPT_LOCAL=""
     [ "$OSRF_HOSTNAME" = "localhost" ] && OPT_LOCAL="-l"
+    set +e # Ignore errors for NXDOMAIN
     opensrf.py -p $OPT_PID_DIR -f $OPT_CONFIG -a stop_all $OPT_LOCAL
+    set -e # Errors matter again
     sleep 1;
     return 0;
 }

Modified: branches/rel_2_0/src/python/opensrf.py.in
===================================================================
--- branches/rel_2_0/src/python/opensrf.py.in	2011-03-30 04:31:28 UTC (rev 2226)
+++ branches/rel_2_0/src/python/opensrf.py.in	2011-03-30 04:34:39 UTC (rev 2227)
@@ -25,6 +25,7 @@
 
 import sys, getopt, os, signal
 import osrf.system, osrf.server, osrf.app, osrf.set, osrf.json
+import dns.resolver
 
 def do_help():
     '''
@@ -83,9 +84,16 @@
     global domain
     global settings
 
-    # connect to the OpenSRF network
-    osrf.system.System.net_connect(
-        config_file = config_file, config_context = config_ctx)
+    try:
+        # connect to the OpenSRF network
+        osrf.system.System.net_connect(
+            config_file = config_file, config_context = config_ctx)
+    except dns.resolver.NXDOMAIN:
+        dnsfail = """
+ERROR: Could not initialize the OpenSRF Python environment. A DNS query
+failed to resolve the network address of the XMPP server.
+"""
+        sys.exit(dnsfail)
 
     if as_localhost:
         domain = 'localhost'



More information about the opensrf-commits mailing list