Handle the common NXDOMAIN problem with Python a bit more gracefully
authordbs <dbs@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 30 Mar 2011 04:31:28 +0000 (04:31 +0000)
committerdbs <dbs@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 30 Mar 2011 04:31:28 +0000 (04:31 +0000)
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.

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2226 9efc2488-bf62-4759-914b-345cdb29e865

bin/osrf_ctl.sh.in
src/python/opensrf.py.in

index 15cba82..23a3fc7 100755 (executable)
@@ -197,7 +197,9 @@ stop_python() {
     [ -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;
 }
index cddbab1..9763b61 100755 (executable)
@@ -25,6 +25,7 @@ Provides an environment for managing OpenSRF services written in Python
 
 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 @@ def do_init():
     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'