def _allow_creating_cluster():
    env = os.path.join(runtime_props['home_dir'], 'env')
    systemd_run = '/usr/bin/systemd-run'
    journalctl = '/usr/bin/journalctl'
    create_cluster_node = os.path.join(env, 'bin/create_cluster_node')
    cluster_unit_name = 'cloudify-ha-cluster'

    command = '{0} --unit {1} {2} --config *'.format(systemd_run,
                                                     cluster_unit_name,
                                                     create_cluster_node)
    description = 'Start a cluster'
    utils.allow_user_to_sudo_command(command, description)

    command = '{0} --unit {1}*'.format(journalctl, cluster_unit_name)
    description = 'Read cluster logs'
    utils.allow_user_to_sudo_command(command, description)
def _allow_creating_cluster():
    env = os.path.join(runtime_props['home_dir'], 'env')
    systemd_run = '/usr/bin/systemd-run'
    journalctl = '/usr/bin/journalctl'
    create_cluster_node = os.path.join(env, 'bin/create_cluster_node')
    cluster_unit_name = 'cloudify-ha-cluster'

    command = '{0} --unit {1} {2} --config *'.format(
        systemd_run,
        cluster_unit_name,
        create_cluster_node
    )
    description = 'Start a cluster'
    utils.allow_user_to_sudo_command(command, description)

    command = '{0} --unit {1}*'.format(journalctl, cluster_unit_name)
    description = 'Read cluster logs'
    utils.allow_user_to_sudo_command(command, description)
def _install_stage():
    nodejs_source_url = ctx_properties['nodejs_tar_source_url']
    stage_source_url = ctx_properties['stage_tar_source_url']

    if not utils.resource_factory.local_resource_exists(stage_source_url):
        ctx.logger.info('Stage package not found in manager resources '
                        'package. Stage will not be installed.')
        ctx.instance.runtime_properties['skip_installation'] = 'true'
        return

    # injected as an input to the script
    ctx.instance.runtime_properties['influxdb_endpoint_ip'] = \
        os.environ.get('INFLUXDB_ENDPOINT_IP')

    utils.set_selinux_permissive()
    utils.copy_notice(SERVICE_NAME)

    utils.mkdir(NODEJS_DIR)
    utils.mkdir(HOME_DIR)
    utils.mkdir(LOG_DIR)
    utils.mkdir(RESOURCES_DIR)

    utils.create_service_user(STAGE_USER, STAGE_GROUP, HOME_DIR)

    ctx.logger.info('Installing NodeJS...')
    nodejs = utils.download_cloudify_resource(nodejs_source_url, SERVICE_NAME)
    utils.untar(nodejs, NODEJS_DIR)
    utils.remove(nodejs)

    ctx.logger.info('Installing Cloudify Stage (UI)...')
    stage_tar = utils.download_cloudify_resource(stage_source_url,
                                                 SERVICE_NAME)
    if 'community' in stage_tar:
        ctx.logger.info('Community edition')
        ctx.instance.runtime_properties['community_mode'] = '-mode community'
    else:
        ctx.instance.runtime_properties['community_mode'] = ''

    utils.untar(stage_tar, HOME_DIR)
    utils.remove(stage_tar)

    ctx.logger.info('Fixing permissions...')
    utils.chown(STAGE_USER, STAGE_GROUP, HOME_DIR)
    utils.chown(STAGE_USER, STAGE_GROUP, NODEJS_DIR)
    utils.chown(STAGE_USER, STAGE_GROUP, LOG_DIR)
    configure_script(
        'restore-snapshot.py',
        'Restore stage directories from a snapshot path',
    )
    configure_script(
        'make-auth-token.py',
        'Update auth token for stage user',
    )
    # Allow snapshot restores to restore token
    utils.allow_user_to_sudo_command(
        '/opt/manager/env/bin/python',
        'Snapshot update auth token for stage user',
        allow_as=STAGE_USER,
    )
    subprocess.check_call([
        'sudo',
        '-u',
        'stage_user',
        '/opt/manager/env/bin/python',
        '/opt/cloudify/stage/make-auth-token.py',
    ])

    utils.logrotate(SERVICE_NAME)
    utils.systemd.configure(SERVICE_NAME)

    backend_dir = join(HOME_DIR, 'backend')
    npm_path = join(NODEJS_DIR, 'bin', 'npm')
    subprocess.check_call('cd {0}; {1} run db-migrate'.format(
        backend_dir, npm_path),
                          shell=True)
示例#4
0
def allow_snapshot_db_secrets_fixer():
    command = '/opt/mgmtworker/resources/cloudify/fix_snapshot_ssh_db'
    description = 'snapshot_ssh_db_fix'
    utils.allow_user_to_sudo_command(command, description)