def setup_server(irods_config, json_configuration_file=None):
    l = logging.getLogger(__name__)

    check_hostname()

    if json_configuration_file is not None:
        with open(json_configuration_file) as f:
            json_configuration_dict = json.load(f)
    else:
        json_configuration_dict = None

    if IrodsController().get_binary_to_pids_dict():
        l.info(irods.lib.get_header('Stopping iRODS...'))
        IrodsController(irods_config).stop()

    if not os.path.exists(irods_config.version_path):
        with open('.'.join([irods_config.version_path, 'dist'])) as f:
            version_json = json.load(f)
        version_json['installation_time'] = datetime.datetime.now().isoformat()
        irods_config.commit(version_json, irods.paths.version_path())

    if json_configuration_dict is not None:
        irods_user = json_configuration_dict['host_system_information']['service_account_user_name']
        irods_group = json_configuration_dict['host_system_information']['service_account_group_name']
    else:
        irods_user, irods_group = get_irods_user_and_group(irods_config)

    setup_service_account(irods_config, irods_user, irods_group)

    #Do the rest of the setup as the irods user
    if os.getuid() == 0:
        irods.lib.switch_user(irods_config.irods_user, irods_config.irods_group)

    if json_configuration_dict is not None:
        irods_config.commit(json_configuration_dict['server_config'], irods.paths.server_config_path())
        if irods_config.is_catalog:
            from irods import database_interface
            if database_interface.database_already_in_use_by_irods(irods_config):
                raise IrodsError('Database specified already in use by iRODS.')
        irods_config.commit(json_configuration_dict['hosts_config'], irods.paths.hosts_config_path())
        irods_config.commit(json_configuration_dict['host_access_control_config'], irods.paths.host_access_control_config_path())
        if not os.path.exists(os.path.dirname(irods_config.client_environment_path)):
            os.makedirs(os.path.dirname(irods_config.client_environment_path), mode=0o700)
        irods_config.commit(json_configuration_dict['service_account_environment'], irods_config.client_environment_path)
        irods_config.admin_password = json_configuration_dict['admin_password']
        default_resource_directory = json_configuration_dict.get('default_resource_directory', os.path.join(irods_config.irods_directory, 'Vault'))
    else:
        determine_server_role(irods_config)

        if irods_config.is_catalog:
            from irods import database_interface
            l.info(irods.lib.get_header('Configuring the database communications'))
            database_interface.setup_database_config(irods_config)

        setup_server_config(irods_config)
        setup_client_environment(irods_config)
        default_resource_directory = get_and_create_default_vault(irods_config)

    if irods_config.is_catalog:
        l.info(irods.lib.get_header('Setting up the database'))
        database_interface.setup_catalog(irods_config, default_resource_directory=default_resource_directory)

    l.info(irods.lib.get_header('Starting iRODS...'))
    IrodsController(irods_config).start()

    if irods_config.is_resource:
        irods.lib.execute_command(['iadmin', 'mkresc', irods_config.server_config['default_resource_name'], 'unixfilesystem', ':'.join([irods.lib.get_hostname(), default_resource_directory]), ''])

    test_put(irods_config)

    l.info(irods.lib.get_header('iRODS is installed and running'))
Exemple #2
0
def setup_server(irods_config, json_configuration_file=None, test_mode=False):
    l = logging.getLogger(__name__)

    check_hostname()

    if json_configuration_file is not None:
        with open(json_configuration_file) as f:
            json_configuration_dict = json.load(f)
    else:
        json_configuration_dict = None

    if IrodsController().get_binary_to_pids_dict():
        l.info(irods.lib.get_header('Stopping iRODS...'))
        IrodsController(irods_config).stop()

    if not os.path.exists(irods_config.version_path):
        with open('.'.join([irods_config.version_path, 'dist'])) as f:
            version_json = json.load(f)
        version_json['installation_time'] = datetime.datetime.now().isoformat()
        irods_config.commit(version_json, irods.paths.version_path())

    if json_configuration_dict is not None:
        irods_user = json_configuration_dict['host_system_information'][
            'service_account_user_name']
        irods_group = json_configuration_dict['host_system_information'][
            'service_account_group_name']
    else:
        irods_user, irods_group = get_irods_user_and_group(irods_config)

    setup_service_account(irods_config, irods_user, irods_group)
    setup_rsyslog_and_logrotate(register_tty=False)

    # Do the rest of the setup as the irods user
    if os.getuid() == 0:
        irods.lib.switch_user(irods_config.irods_user,
                              irods_config.irods_group)

    if json_configuration_dict is not None:
        irods_config.commit(json_configuration_dict['server_config'],
                            irods.paths.server_config_path())
        if irods_config.is_catalog:
            from irods import database_interface
            if database_interface.database_already_in_use_by_irods(
                    irods_config):
                raise IrodsError('Database specified already in use by iRODS.')
        irods_config.commit(json_configuration_dict['hosts_config'],
                            irods.paths.hosts_config_path())
        irods_config.commit(
            json_configuration_dict['host_access_control_config'],
            irods.paths.host_access_control_config_path())
        if not os.path.exists(
                os.path.dirname(irods_config.client_environment_path)):
            os.makedirs(os.path.dirname(irods_config.client_environment_path),
                        mode=0o700)
        irods_config.commit(
            json_configuration_dict['service_account_environment'],
            irods_config.client_environment_path)
        irods_config.admin_password = json_configuration_dict['admin_password']
        default_resource_directory = json_configuration_dict.get(
            'default_resource_directory',
            os.path.join(irods_config.irods_directory, 'Vault'))
    else:
        determine_server_role(irods_config)

        if irods_config.is_catalog:
            from irods import database_interface
            l.info(
                irods.lib.get_header(
                    'Configuring the database communications'))
            database_interface.setup_database_config(irods_config)

        setup_server_config(irods_config)
        setup_client_environment(irods_config)
        default_resource_directory = get_and_create_default_vault(irods_config)

    if irods_config.is_catalog:
        l.info(irods.lib.get_header('Setting up the database'))
        database_interface.setup_catalog(
            irods_config,
            default_resource_directory=default_resource_directory)

    l.info(irods.lib.get_header('Starting iRODS...'))
    IrodsController(irods_config).start(test_mode=test_mode)

    if irods_config.is_resource:
        irods.lib.execute_command([
            'iadmin', 'mkresc',
            irods_config.server_config['default_resource_name'],
            'unixfilesystem',
            ':'.join([irods.lib.get_hostname(),
                      default_resource_directory]), ''
        ])

    test_put(irods_config)

    l.info(irods.lib.get_header('Log Configuration Notes'))
    l.info((
        'The iRODS log file is managed by rsyslog and logrotate.\n'
        'The locations of the log file and configuration files are listed below.\n\n'
        '  Log File Path               : ' + irods.paths.server_log_path() +
        '\n'
        '  Rsyslog Configuration Path  : ' + rsyslog_config_path() + '\n'
        '  Logrotate Configuration Path: ' + logrotate_config_path() + '\n\n'
        'iRODS will never touch these configuration files again.\n'
        'If you need to make adjustments, you must do so manually.'))

    l.info(irods.lib.get_header('Stopping iRODS...'))
    IrodsController(irods_config).stop()

    l.info(irods.lib.get_header('iRODS is configured and ready to be started'))