Fix path detection.
Change-Id: If76969e6c753596fff885fdb021ba53b1537c945
This commit is contained in:
parent
1d25eeffdd
commit
449bdcd48b
@ -27,16 +27,12 @@ import sys
|
|||||||
import argparse
|
import argparse
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
# Pathes magic to make python find out stuff.
|
|
||||||
# also remember our basepath (for etc, pid lookup, etc)
|
|
||||||
basepath = path.abspath(path.join(sys.path[0], '..'))
|
|
||||||
etc_path = path.join(basepath, 'etc')
|
|
||||||
pid_path = path.join(basepath, 'pid')
|
|
||||||
log_path = path.join(basepath, 'log')
|
|
||||||
#sys.path[0] = path.join(basepath, 'src')
|
|
||||||
sys.path[0] = basepath
|
|
||||||
|
|
||||||
import mlzlog
|
import mlzlog
|
||||||
|
|
||||||
|
# Add import path for inplace usage
|
||||||
|
sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..')))
|
||||||
|
|
||||||
|
from secop.lib import getGeneralConfig
|
||||||
from secop.server import Server
|
from secop.server import Server
|
||||||
|
|
||||||
|
|
||||||
@ -67,9 +63,9 @@ def main(argv=None):
|
|||||||
args = parseArgv(argv[1:])
|
args = parseArgv(argv[1:])
|
||||||
|
|
||||||
loglevel = 'debug' if args.verbose else ('error' if args.quiet else 'info')
|
loglevel = 'debug' if args.verbose else ('error' if args.quiet else 'info')
|
||||||
mlzlog.initLogging('secop', loglevel, log_path)
|
mlzlog.initLogging('secop', loglevel, getGeneralConfig()['logdir'])
|
||||||
|
|
||||||
srv = Server(args.name, basepath, mlzlog.log)
|
srv = Server(args.name, mlzlog.log)
|
||||||
|
|
||||||
if args.daemonize:
|
if args.daemonize:
|
||||||
srv.start()
|
srv.start()
|
||||||
|
@ -36,6 +36,20 @@ import unicodedata
|
|||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
|
|
||||||
|
repodir = path.abspath(path.join(path.dirname(__file__), '..', '..'))
|
||||||
|
|
||||||
|
CONFIG = {
|
||||||
|
'piddir': os.path.join(repodir, 'pid'),
|
||||||
|
'logdir': os.path.join(repodir, 'log'),
|
||||||
|
'confdir': os.path.join(repodir, 'etc'),
|
||||||
|
} if os.path.exists(os.path.join(repodir, '.git')) else {
|
||||||
|
'piddir': '/var/run/secop',
|
||||||
|
'logdir': '/var/log/secop',
|
||||||
|
'confdir': '/etc/secop',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class lazy_property(object):
|
class lazy_property(object):
|
||||||
"""A property that calculates its value only once."""
|
"""A property that calculates its value only once."""
|
||||||
|
|
||||||
@ -223,10 +237,5 @@ def getfqdn(name=''):
|
|||||||
return socket.getfqdn(name)
|
return socket.getfqdn(name)
|
||||||
|
|
||||||
|
|
||||||
# if __name__ == '__main__':
|
def getGeneralConfig():
|
||||||
# print "minimal testing: lib"
|
return CONFIG
|
||||||
# d = attrdict(a=1, b=2)
|
|
||||||
# _ = d.a + d['b']
|
|
||||||
# d.c = 9
|
|
||||||
# d['d'] = 'c'
|
|
||||||
# assert d[d.d] == 9
|
|
||||||
|
@ -35,24 +35,22 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
import daemon.pidfile as pidlockfile
|
import daemon.pidfile as pidlockfile
|
||||||
|
|
||||||
from secop.lib import get_class, formatException
|
from secop.lib import get_class, formatException, getGeneralConfig
|
||||||
from secop.protocol.dispatcher import Dispatcher
|
from secop.protocol.dispatcher import Dispatcher
|
||||||
from secop.protocol.interface import INTERFACES
|
from secop.protocol.interface import INTERFACES
|
||||||
#from secop.protocol.encoding import ENCODERS
|
|
||||||
#from secop.protocol.framing import FRAMERS
|
|
||||||
from secop.errors import ConfigError
|
from secop.errors import ConfigError
|
||||||
|
|
||||||
|
|
||||||
class Server(object):
|
class Server(object):
|
||||||
|
|
||||||
def __init__(self, name, workdir, parentLogger=None):
|
def __init__(self, name, parentLogger=None):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._workdir = workdir
|
|
||||||
|
|
||||||
self.log = parentLogger.getChild(name, True)
|
self.log = parentLogger.getChild(name, True)
|
||||||
|
|
||||||
self._pidfile = os.path.join(workdir, 'pid', name + '.pid')
|
cfg = getGeneralConfig()
|
||||||
self._cfgfile = os.path.join(workdir, 'etc', name + '.cfg')
|
self._pidfile = os.path.join(cfg['piddir'], name + '.pid')
|
||||||
|
self._cfgfile = os.path.join(cfg['confdir'], name + '.cfg')
|
||||||
|
|
||||||
self._dispatcher = None
|
self._dispatcher = None
|
||||||
self._interface = None
|
self._interface = None
|
||||||
@ -67,7 +65,6 @@ class Server(object):
|
|||||||
self.log.error('Pidfile already exists. Exiting')
|
self.log.error('Pidfile already exists. Exiting')
|
||||||
|
|
||||||
with DaemonContext(
|
with DaemonContext(
|
||||||
working_directory=self._workdir,
|
|
||||||
pidfile=pidfile,
|
pidfile=pidfile,
|
||||||
files_preserve=self.log.getLogfileStreams()):
|
files_preserve=self.log.getLogfileStreams()):
|
||||||
self.run()
|
self.run()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user