Fix path detection.
Change-Id: If76969e6c753596fff885fdb021ba53b1537c945
This commit is contained in:
parent
1d25eeffdd
commit
449bdcd48b
@ -27,16 +27,12 @@ import sys
|
||||
import argparse
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
@ -67,9 +63,9 @@ def main(argv=None):
|
||||
args = parseArgv(argv[1:])
|
||||
|
||||
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:
|
||||
srv.start()
|
||||
|
@ -36,6 +36,20 @@ import unicodedata
|
||||
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):
|
||||
"""A property that calculates its value only once."""
|
||||
|
||||
@ -223,10 +237,5 @@ def getfqdn(name=''):
|
||||
return socket.getfqdn(name)
|
||||
|
||||
|
||||
# if __name__ == '__main__':
|
||||
# print "minimal testing: lib"
|
||||
# d = attrdict(a=1, b=2)
|
||||
# _ = d.a + d['b']
|
||||
# d.c = 9
|
||||
# d['d'] = 'c'
|
||||
# assert d[d.d] == 9
|
||||
def getGeneralConfig():
|
||||
return CONFIG
|
||||
|
@ -35,24 +35,22 @@ try:
|
||||
except ImportError:
|
||||
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.interface import INTERFACES
|
||||
#from secop.protocol.encoding import ENCODERS
|
||||
#from secop.protocol.framing import FRAMERS
|
||||
from secop.errors import ConfigError
|
||||
|
||||
|
||||
class Server(object):
|
||||
|
||||
def __init__(self, name, workdir, parentLogger=None):
|
||||
def __init__(self, name, parentLogger=None):
|
||||
self._name = name
|
||||
self._workdir = workdir
|
||||
|
||||
self.log = parentLogger.getChild(name, True)
|
||||
|
||||
self._pidfile = os.path.join(workdir, 'pid', name + '.pid')
|
||||
self._cfgfile = os.path.join(workdir, 'etc', name + '.cfg')
|
||||
cfg = getGeneralConfig()
|
||||
self._pidfile = os.path.join(cfg['piddir'], name + '.pid')
|
||||
self._cfgfile = os.path.join(cfg['confdir'], name + '.cfg')
|
||||
|
||||
self._dispatcher = None
|
||||
self._interface = None
|
||||
@ -67,7 +65,6 @@ class Server(object):
|
||||
self.log.error('Pidfile already exists. Exiting')
|
||||
|
||||
with DaemonContext(
|
||||
working_directory=self._workdir,
|
||||
pidfile=pidfile,
|
||||
files_preserve=self.log.getLogfileStreams()):
|
||||
self.run()
|
||||
|
Loading…
x
Reference in New Issue
Block a user