Source code for cobbler.cobblerd

Cobbler daemon for logging remote syslog traffic during automatic installation

# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: Copyright 2007-2009, Red Hat, Inc and Others
# SPDX-FileCopyrightText: Michael DeHaan <michael.dehaan AT gmail>

import binascii
import logging.config
import os
import pwd
import time

from cobbler import remote, utils
from cobbler.api import CobblerAPI

if os.geteuid() == 0 and os.path.exists("/etc/cobbler/logging_config.conf"):

logger = logging.getLogger()

[docs]def core(cobbler_api: CobblerAPI): """ Starts Cobbler. :param cobbler_api: The cobbler_api instance which is used for this method. """ settings = cobbler_api.settings() xmlrpc_port = settings.xmlrpc_port regen_ss_file() do_xmlrpc_rw(cobbler_api, xmlrpc_port)
[docs]def regen_ss_file(): """ This is only used for Kerberos auth at the moment. It identifies XMLRPC requests from Apache that have already been cleared by Kerberos. """ ssfile = "/var/lib/cobbler/" with open("/dev/urandom", "rb") as fd: data = with open(ssfile, "wb", 0o660) as fd: fd.write(binascii.hexlify(data)) http_user = "apache" family = utils.get_family() if family == "debian": http_user = "www-data" elif family == "suse": http_user = "wwwrun" os.lchown("/var/lib/cobbler/", pwd.getpwnam(http_user)[2], -1)
[docs]def do_xmlrpc_rw(cobbler_api: CobblerAPI, port): """ This trys to bring up the Cobbler xmlrpc_api and restart it if it fails. :param cobbler_api: The cobbler_api instance which is used for this method. :param port: The port where the xmlrpc api should run on. """ xinterface = remote.ProxiedXMLRPCInterface( cobbler_api, remote.CobblerXMLRPCInterface ) server = remote.CobblerXMLRPCServer(("", port)) server.logRequests = 0 # don't print stuff logger.debug("XMLRPC running on %s", port) server.register_instance(xinterface) start_time = "" try: import psutil p = psutil.Process(os.getpid()) start_time = " in %s seconds" % str(time.time() - p.create_time()) except ModuleNotFoundError: # This is not critical, but debug only - just install python3-psutil pass while True: try:"Cobbler startup completed %s", start_time) server.serve_forever() except IOError: # interrupted? try to serve again time.sleep(0.5)
if __name__ == "__main__": core(CobblerAPI())