Skip to content
Snippets Groups Projects
Commit c0c03dad authored by Henrik Thostrup Jensen's avatar Henrik Thostrup Jensen
Browse files

set logfile in application creation and not at twistd (this is slighly more...

set logfile in application creation and not at twistd (this is slighly more flexible and saves an init.d hack)
parent 2f06d536
No related branches found
No related tags found
No related merge requests found
......@@ -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() {
......
......@@ -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'
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment