Changeset View
Changeset View
Standalone View
Standalone View
kolabd/__init__.py
# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com) | # Copyright 2010-2016 Kolab Systems AG (http://www.kolabsys.com) | ||||
# | # | ||||
# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> | # Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com> | ||||
# | # | ||||
# This program is free software: you can redistribute it and/or modify | # This program is free software: you can redistribute it and/or modify | ||||
# it under the terms of the GNU General Public License as published by | # it under the terms of the GNU General Public License as published by | ||||
# the Free Software Foundation, either version 3 of the License, or | # the Free Software Foundation, either version 3 of the License, or | ||||
# (at your option) any later version. | # (at your option) any later version. | ||||
Show All 25 Lines | |||||
from pykolab import utils | from pykolab import utils | ||||
from pykolab.translate import _ | from pykolab.translate import _ | ||||
from process import KolabdProcess as Process | from process import KolabdProcess as Process | ||||
log = pykolab.getLogger('pykolab.daemon') | log = pykolab.getLogger('pykolab.daemon') | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
class KolabDaemon(object): | class KolabDaemon(object): | ||||
def __init__(self): | def __init__(self): | ||||
""" | """ | ||||
The main Kolab Groupware daemon process. | The main Kolab Groupware daemon process. | ||||
""" | """ | ||||
daemon_group = conf.add_cli_parser_option_group(_("Daemon Options")) | daemon_group = conf.add_cli_parser_option_group(_("Daemon Options")) | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | def run(self): | ||||
except KeyError: | except KeyError: | ||||
print >> sys.stderr, _("User %s does not exist") % ( | print >> sys.stderr, _("User %s does not exist") % ( | ||||
conf.process_username | conf.process_username | ||||
) | ) | ||||
sys.exit(1) | sys.exit(1) | ||||
# Set real and effective user if not the same as current. | # Set real and effective user if not the same as current. | ||||
if not user_uid == ruid: | if not user_uid == ruid: | ||||
log.debug( | log.debug( | ||||
_("Switching real and effective user id to %d") % ( | _("Switching real and effective user id to %d") % ( | ||||
user_uid | user_uid | ||||
), | ), | ||||
level=8 | level=8 | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def run(self): | ||||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||||
exitcode = 1 | exitcode = 1 | ||||
log.info(_("Interrupted by user")) | log.info(_("Interrupted by user")) | ||||
except AttributeError, errmsg: | except AttributeError, errmsg: | ||||
exitcode = 1 | exitcode = 1 | ||||
traceback.print_exc() | traceback.print_exc() | ||||
print >> sys.stderr, _("Traceback occurred, please report a " + \ | print >> sys.stderr, _("Traceback occurred, please report a " + | ||||
"bug at https://issues.kolab.org") | "bug at https://issues.kolab.org") | ||||
except TypeError, errmsg: | except TypeError, errmsg: | ||||
exitcode = 1 | exitcode = 1 | ||||
traceback.print_exc() | traceback.print_exc() | ||||
log.error(_("Type Error: %s") % errmsg) | log.error(_("Type Error: %s") % errmsg) | ||||
except: | except: | ||||
exitcode = 2 | exitcode = 2 | ||||
traceback.print_exc() | traceback.print_exc() | ||||
print >> sys.stderr, _("Traceback occurred, please report a " + \ | print >> sys.stderr, _("Traceback occurred, please report a " + | ||||
"bug at https://issues.kolab.org") | "bug at https://issues.kolab.org") | ||||
sys.exit(exitcode) | sys.exit(exitcode) | ||||
def do_sync(self): | def do_sync(self): | ||||
domain_auth = {} | domain_auth = {} | ||||
pid = os.getpid() | pid = os.getpid() | ||||
Show All 30 Lines | def do_sync(self): | ||||
# domains now is a list of tuples in the format of | # domains now is a list of tuples in the format of | ||||
# ('primary',[secondaries]), we want the primary_domains | # ('primary',[secondaries]), we want the primary_domains | ||||
domain_base_dns = [] | domain_base_dns = [] | ||||
primary_domains = [] | primary_domains = [] | ||||
for primary_domain in list(set(domains.values())): | for primary_domain in list(set(domains.values())): | ||||
domain_base_dn = primary_auth.domain_naming_context(primary_domain) | domain_base_dn = primary_auth.domain_naming_context(primary_domain) | ||||
log.debug(_("Domain Base DN for domain %r is %r") % (primary_domain, domain_base_dn), level=8) | log.debug(_("Domain Base DN for domain %r is %r") % (primary_domain, domain_base_dn), level=8) | ||||
if not domain_base_dn == None: | if domain_base_dn is not None: | ||||
if not domain_base_dn in domain_base_dns: | if domain_base_dn not in domain_base_dns: | ||||
domain_base_dns.append(domain_base_dn) | domain_base_dns.append(domain_base_dn) | ||||
primary_domain = primary_auth.primary_domain_for_naming_context(domain_base_dn) | primary_domain = primary_auth.primary_domain_for_naming_context(domain_base_dn) | ||||
primary_domains.append(primary_domain) | primary_domains.append(primary_domain) | ||||
log.debug(_("Naming contexts to synchronize: %r") % (primary_domains), level=8) | log.debug(_("Naming contexts to synchronize: %r") % (primary_domains), level=8) | ||||
# Now we can check if any changes happened. | # Now we can check if any changes happened. | ||||
added_domains = [] | added_domains = [] | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | class KolabDaemon(object): | ||||
def set_signal_handlers(self): | def set_signal_handlers(self): | ||||
import signal | import signal | ||||
signal.signal(signal.SIGHUP, self.reload_config) | signal.signal(signal.SIGHUP, self.reload_config) | ||||
signal.signal(signal.SIGTERM, self.remove_pid) | signal.signal(signal.SIGTERM, self.remove_pid) | ||||
def write_pid(self): | def write_pid(self): | ||||
pid = os.getpid() | pid = os.getpid() | ||||
fp = open(conf.pidfile,'w') | fp = open(conf.pidfile, 'w') | ||||
fp.write("%d\n" % (pid)) | fp.write("%d\n" % (pid)) | ||||
fp.close() | fp.close() |