From 014c44a4572c5c66cfba151d1a9887e05361a3db Mon Sep 17 00:00:00 2001 From: dbs Date: Wed, 30 Mar 2011 04:31:28 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2226 9efc2488-bf62-4759-914b-345cdb29e865 --- bin/osrf_ctl.sh.in | 2 ++ src/python/opensrf.py.in | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/osrf_ctl.sh.in b/bin/osrf_ctl.sh.in index 15cba82..23a3fc7 100755 --- a/bin/osrf_ctl.sh.in +++ b/bin/osrf_ctl.sh.in @@ -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; } diff --git a/src/python/opensrf.py.in b/src/python/opensrf.py.in index cddbab1..9763b61 100755 --- a/src/python/opensrf.py.in +++ b/src/python/opensrf.py.in @@ -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' -- 2.43.2