From c0c03dada46172318c84865f92b6a72f55c04bb2 Mon Sep 17 00:00:00 2001 From: Henrik Thostrup Jensen <htj@nordu.net> Date: Tue, 20 Dec 2011 13:00:05 +0100 Subject: [PATCH] set logfile in application creation and not at twistd (this is slighly more flexible and saves an init.d hack) --- datafiles/opennsa | 7 +------ opennsa/config.py | 1 + opennsa/setup.py | 10 ++++++++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/datafiles/opennsa b/datafiles/opennsa index 5c2d3a41..acbb26e0 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 04da24e8..243ffe34 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 bbfe6501..27aea25a 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) -- GitLab