Пример #1
0
    def _get_service_manager(cfg, pulp_host):
        """Talk to the target host and determine the type of service manager.

        Return "systemd" or "sysv" if the service manager appears to be one of
        those. Raise an exception otherwise.
        """
        try:
            return _SERVICE_MANAGERS[pulp_host.hostname]
        except KeyError:
            pass

        client = Client(cfg, echo_handler, pulp_host=pulp_host)
        commands_managers = (
            ("which systemctl", "systemd"),
            ("which service", "sysv"),
            ("test -x /sbin/service", "sysv"),
        )
        for command, service_manager in commands_managers:
            if client.run(command.split()).returncode == 0:
                _SERVICE_MANAGERS[pulp_host.hostname] = service_manager
                return service_manager
        raise exceptions.NoKnownServiceManagerError(
            "Unable to determine the service manager used by {}. It does not "
            "appear to be any of {}.".format(
                pulp_host.hostname,
                {manager
                 for _, manager in commands_managers},
            ))
Пример #2
0
    def _get_service_manager(server_config):
        """Talk to the target system and determine the type of service manager.

        Return "systemd" or "sysv" if the service manager appears to be one of
        those. Raise an exception otherwise.
        """
        hostname = _get_hostname(server_config.base_url)
        try:
            return _SERVICE_MANAGERS[hostname]
        except KeyError:
            pass

        client = Client(server_config, echo_handler)
        commands_managers = (
            ('which systemctl', 'systemd'),
            ('which service', 'sysv'),
            ('test -x /sbin/service', 'sysv'),
        )
        for command, service_manager in commands_managers:
            run = client.run(command.split())
            print(run)
            if client.run(command.split()).returncode == 0:
                _SERVICE_MANAGERS[hostname] = service_manager
                print (_SERVICE_MANAGERS)
                return service_manager
        raise exceptions.NoKnownServiceManagerError(
            'Unable to determine the service manager used by {}. It does not '
            'appear to be any of {}.'
            .format(hostname, {manager for _, manager in commands_managers})
        )