diff --git a/datafiles/opennsa b/datafiles/opennsa index 5c2d3a41f9f3d49d0858e2c8dc625951a36f3a70..acbb26e07915161492653691522c583da6c1e917 100755 --- a/datafiles/opennsa +++ b/datafiles/opennsa @@ -18,16 +18,11 @@ CONFIG_FILE=/etc/opennsa.conf PIDFILE=/var/run/opennsa.pid -DEFAULT_LOGFILE=/var/log/opennsa.log DEFAULT_USER=root APP_START="from opennsa import setup ; application = setup.createApplication()" do_start() { - # get logfile from config file or set to default if not found - LOGFILE=`grep ^logfile= $CONFIG_FILE | tail -n 1 | cut -f2 -d'='` - LOGFILE=${LOGFILE:-$DEFAULT_LOGFILE} - # get runtime user from config file or set to root if not found USER=`grep ^user= $CONFIG_FILE | tail -n 1 | cut -f2 -d'='` USER=${USER:-$DEFAULT_USER} @@ -39,7 +34,7 @@ do_start() { echo $APP_START > $TACFILE # start the opennsa service using twistd - twistd --pidfile $PIDFILE -l $LOGFILE -y $TACFILE -u $USER_ID -g $GROUP_ID + twistd --pidfile $PIDFILE -y $TACFILE -u $USER_ID -g $GROUP_ID } do_stop() { diff --git a/opennsa/config.py b/opennsa/config.py index 04da24e83efddc1029e03412a05d5c0a12bc1e3e..243ffe348c0f61064e4584a96099a80af840e0a8 100644 --- a/opennsa/config.py +++ b/opennsa/config.py @@ -27,6 +27,7 @@ BLOCK_ARGIA = 'argia' # service block CONFIG_NETWORK_NAME = 'network' # mandatory +CONFIG_LOG_FILE = 'logfile' CONFIG_HOST = 'host' CONFIG_PORT = 'port' CONFIG_TOPOLOGY_FILE = 'topology' diff --git a/opennsa/setup.py b/opennsa/setup.py index bbfe6501fbefe921046f6cae417267a4c55be5ab..27aea25a7292c50ba20b821d90058d7fc0138675 100644 --- a/opennsa/setup.py +++ b/opennsa/setup.py @@ -3,7 +3,6 @@ High-level functionality for creating clients and services in OpenNSA. """ import os -import sys from ConfigParser import NoOptionError from twisted.python.log import ILogObserver @@ -77,6 +76,13 @@ def createApplication(config_file=config.DEFAULT_CONFIG_FILE, tls=True, authz_ve except NoOptionError: raise ConfigurationError('No network name specified in configuration file (mandatory)') + log_file_path = cfg.get(config.BLOCK_SERVICE, config.CONFIG_LOG_FILE) + if log_file_path: + log_file = open(log_file_path, 'w') + else: + import sys + log_file = sys.stdout + topology_file = cfg.get(config.BLOCK_SERVICE, config.CONFIG_TOPOLOGY_FILE) if not os.path.exists(topology_file): raise ConfigurationError('Specified (or default) topology file does not exist (%s)' % topology_file) @@ -127,7 +133,7 @@ def createApplication(config_file=config.DEFAULT_CONFIG_FILE, tls=True, authz_ve factory = createService(network_name, open(topology_file), backend, host, port, wsdl_dir, ctx_factory) application = appservice.Application("OpenNSA") - application.setComponent(ILogObserver, logging.DebugLogObserver(sys.stdout, debug).emit) + application.setComponent(ILogObserver, logging.DebugLogObserver(log_file, debug).emit) if tls: internet.SSLServer(port, factory, ctx_factory).setServiceParent(application)