当前位置: 首页>>代码示例>>Python>>正文


Python operations.sudo方法代码示例

本文整理汇总了Python中fabric.operations.sudo方法的典型用法代码示例。如果您正苦于以下问题:Python operations.sudo方法的具体用法?Python operations.sudo怎么用?Python operations.sudo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fabric.operations的用法示例。


在下文中一共展示了operations.sudo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pip_install

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def pip_install(cmd_prefix, requirements, timeout=None, quiet=False, proxy=None, no_index=False,
        wheel_dir=None):
    parts = [cmd_prefix, 'pip install']
    if timeout is not None:
        parts.append('--timeout {}'.format(timeout))
    if quiet:
        parts.append('--quiet')
    for requirement in requirements:
        parts.append('--requirement {}'.format(requirement))
    if proxy is not None:
        parts.append('--proxy {}'.format(proxy))
    if no_index:
        parts.append('--no-index')
    if wheel_dir is not None:
        parts.append('--find-links={}'.format(wheel_dir))
    sudo(' '.join(parts)) 
开发者ID:dimagi,项目名称:commcare-cloud,代码行数:18,代码来源:utils.py

示例2: setup_supervisor

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def setup_supervisor():
    """Setup supervisor daemon for running OCL processes.

    One of the key function is to put the API tokens required in the
    environment for Web server.
     """

    # first time this will fail because we have a chicken and egg
    # situation, we need the API server to get the tokens, but
    # we need supervisor to run the API server
    auth_token, anon_token = get_api_tokens()
    if auth_token is not None and anon_token is not None:
        env.OCL_API_TOKEN = auth_token
        env.OCL_ANON_API_TOKEN = anon_token
    files.upload_template(_conf_path('ocl_supervisor.conf'),
                          '/etc/supervisor/conf.d', env, use_sudo=True)
    put(_conf_path('supervisord.conf'), '/etc/supervisor', use_sudo=True)
    # restart to run as deploy
    sudo('/etc/init.d/supervisor restart') 
开发者ID:OpenConceptLab,项目名称:ocl_web,代码行数:21,代码来源:fabfile.py

示例3: setup_nginx

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def setup_nginx():
    """Setup nginx.

    This can be re-run to update the application configuration via
    the ocl_nginx.conf.
    """
    with settings(warn_only=True):
        sudo('unlink /etc/nginx/sites-enabled/default')

    files.upload_template(_conf_path('ocl_nginx.conf'),
                          '/etc/nginx/sites-available/ocl', env, use_sudo=True)

    with settings(warn_only=True):
        sudo('ln -s /etc/nginx/sites-available/ocl /etc/nginx/sites-enabled/ocl')

    sudo('/etc/init.d/nginx restart') 
开发者ID:OpenConceptLab,项目名称:ocl_web,代码行数:18,代码来源:fabfile.py

示例4: setup_environment

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def setup_environment():
    """Create OCL directories and files.
    """
    for directory in ['/opt/virtualenvs', '/opt/deploy']:
        if not files.exists(directory):
            print yellow('Creating directory %s...' % directory)
            sudo('mkdir %s' % directory)
            sudo('chown deploy:deploy %s' % directory)

    # all logs go to /var/log/ocl subdirectories.
    if not files.exists('/var/log/ocl'):
        sudo('mkdir /var/log/ocl')
        sudo('chown deploy:deploy /var/log/ocl')

    # This backup dir is used by the current API server deployment
    # process.
    if not files.exists(BACKUP_DIR):
        sudo('mkdir -p %s' % BACKUP_DIR)
        sudo('chown deploy:deploy %s' % BACKUP_DIR)

    # A few shell aliases that PK likes...
    put(_conf_path('ocl_aliases'), '~/.bash_aliases')
    put(_conf_path('tmux.conf'), '~/.tmux.conf') 
开发者ID:OpenConceptLab,项目名称:ocl_web,代码行数:25,代码来源:fabfile.py

示例5: fix_solr

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def fix_solr():
    """ Fix solr
        work in progress
    """
    with cd('/var/tmp'):
        print blue('pulling new code...')
        sudo('/etc/init.d/jetty stop')
        sleep(5)
        # run('rm -rf /opt/deploy/solr/collection1')

        print blue('copying new code...')
        # run('mkdir -p /opt/deploy/solr/collection1')
        # run("cp -r oclapi/solr/collection1/conf /opt/deploy/solr/collection1")

    with cd("/opt/deploy/ocl_api/ocl"):
        # there is no need for this, settings.py.eploy is actually wrong?
        # run("cp settings.py.deploy settings.py")
        with prefix('source /opt/virtualenvs/ocl_api/bin/activate'):
            with prefix('export DJANGO_CONFIGURATION="Production"'):
                with prefix('export DJANGO_SECRET_KEY="blah"'):
                    # this is really slow because it pull down django-norel
                    run('./manage.py build_solr_schema > ' +
                        '/opt/deploy/solr/collection1/conf/schema.xml')
    sleep(5)
    sudo('/etc/init.d/jetty start') 
开发者ID:OpenConceptLab,项目名称:ocl_web,代码行数:27,代码来源:fabfile.py

示例6: secure_create_file

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def secure_create_file(filepath, user_group, mode=600):
    user, group = user_group.split(':')
    missing_owner_code = 42
    command = \
        "( getent passwd {user} >/dev/null || exit {missing_owner_code} ) &&" \
        " echo '' > {filepath} && " \
        "chown {user_group} {filepath} && " \
        "chmod {mode} {filepath} ".format(
            filepath=filepath, user=user, user_group=user_group, mode=mode,
            missing_owner_code=missing_owner_code)

    with settings(warn_only=True):
        result = sudo(command)
        if result.return_code == missing_owner_code:
            abort("User %s does not exist. Make sure the Presto server RPM "
                  "is installed and try again" % user)
        elif result.failed:
            abort("Failed to securely create file %s" % (filepath)) 
开发者ID:prestodb,项目名称:presto-admin,代码行数:20,代码来源:deploy.py

示例7: secure_create_directory

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def secure_create_directory(filepath, user_group, mode=755):
    user, group = user_group.split(':')
    missing_owner_code = 42
    command = \
        "( getent passwd {user} >/dev/null || exit {missing_owner_code} ) && " \
        "mkdir -p {filepath} && " \
        "chown {user_group} {filepath} && " \
        "chmod {mode} {filepath} ".format(
            filepath=filepath, user=user, user_group=user_group, mode=mode,
            missing_owner_code=missing_owner_code)

    with settings(warn_only=True):
        result = sudo(command)
        if result.return_code == missing_owner_code:
            abort("User %s does not exist. Make sure the Presto server RPM "
                  "is installed and try again" % user)
        elif result.failed:
            abort("Failed to securely create file %s" % (filepath)) 
开发者ID:prestodb,项目名称:presto-admin,代码行数:20,代码来源:deploy.py

示例8: deploy_node_properties

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def deploy_node_properties(content, remote_dir):
    _LOGGER.info("Deploying node.properties configuration")
    name = "node.properties"
    node_file_path = (os.path.join(remote_dir, name))
    if not exists(node_file_path, use_sudo=True):
        secure_create_file(node_file_path, PRESTO_STANDALONE_USER_GROUP, mode=600)
    else:
        sudo('chown %(owner)s %(filepath)s && chmod %(mode)s %(filepath)s'
             % {'owner': PRESTO_STANDALONE_USER_GROUP, 'mode': 600, 'filepath': node_file_path})
    node_id_command = (
        "if ! ( grep -q -s 'node.id' " + node_file_path + " ); then "
        "uuid=$(uuidgen); "
        "echo node.id=$uuid >> " + node_file_path + ";"
        "fi; "
        "sed -i '/node.id/!d' " + node_file_path + "; "
        )
    sudo(node_id_command)
    files.append(os.path.join(remote_dir, name), content, True, shell=True) 
开发者ID:prestodb,项目名称:presto-admin,代码行数:20,代码来源:deploy.py

示例9: gather_config_directory

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def gather_config_directory():
    """
    For the benefit of the next person to hack this, a list of some things
    that didn't work:
    - passing combine_stderr=False to sudo. Dunno why, still got them
    combined in the output.
    - using a StringIO object cfg = StringIO() and passing stdout=cfg. Got
    the host information at the start of the line.
    - sucking the tar archive over the network into memory instead of
    writing it out to a temporary file on the remote host. Since fabric
    doesn't provide a stdin= kwarg, there's no way to send back a tar
    archive larger than we can fit in a single bash command (~2MB on a
    good day), meaning if /etc/presto contains any large files, we'd end
    up having to send the archive to a temp file anyway.
    """
    result = sudo(
        'tarfile=`mktemp /tmp/presto_config-XXXXXXX.tar`; '
        'tar -c -z -C %s -f "${tarfile}" . && echo "${tarfile}"' % (
            constants.REMOTE_CONF_DIR,))
    return result 
开发者ID:prestodb,项目名称:presto-admin,代码行数:22,代码来源:configure_cmds.py

示例10: single_line_stdout

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def single_line_stdout(cmd, expected_errors=(), shell=True, sudo=False, quiet=False):
    """
    Runs a command and returns the first line of the result, that would be written to `stdout`, as a string.
    The output itself can be suppressed.

    :param cmd: Command to run.
    :type cmd: unicode
    :param expected_errors: If the return code is non-zero, but found in this tuple, it will be ignored. ``None`` is
      returned in this case.
    :type expected_errors: tuple
    :param shell: Use a shell.
    :type shell: bool
    :param sudo: Use `sudo`.
    :type sudo: bool
    :param quiet: If set to ``True``, does not show any output.
    :type quiet: bool
    :return: The result of the command as would be written to `stdout`.
    :rtype: unicode
    """
    return single_line(stdout_result(cmd, expected_errors, shell, sudo, quiet)) 
开发者ID:merll,项目名称:docker-fabric,代码行数:22,代码来源:output.py

示例11: last_commit_sha

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def last_commit_sha(self):
        if self.last_tag:
            return self.last_tag.commit.sha

        with cd(env.code_current):
            return sudo('git rev-parse HEAD') 
开发者ID:dimagi,项目名称:commcare-cloud,代码行数:8,代码来源:utils.py

示例12: bower_command

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def bower_command(command, production=True, config=None):
    cmd = generate_bower_command(command, production, config)
    sudo(cmd) 
开发者ID:dimagi,项目名称:commcare-cloud,代码行数:5,代码来源:utils.py

示例13: add_deploy_user

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def add_deploy_user():
    """Create the deploy user account, one time task.

    The deploy user is used for almost all processes.
    Your SSH key is pushed so that you can login via ssh keys.
    """
    username = 'deploy'
    with settings(user='root'):

        # Create the user, no password
        fastprint('adding the %s user account...' % username)
        run('useradd -m -s /bin/bash %s' % username)
        run('adduser %s sudo' % username)

        # Allow this user to sudo without password
        # really should list specific command (the last ALL)
        files.append('/etc/sudoers.d/%s' % username,
                     '%s ALL=(ALL:ALL) NOPASSWD: ALL' % username)

        fastprint('setting up SSH')
        ssh_path = '/home/%s/.ssh' % username
        if not files.exists(ssh_path, verbose=True):
            run('mkdir %s' % ssh_path)
            run('chmod 700 %s' % ssh_path)

            key_text = _read_key_file('~/.ssh/id_rsa.pub')
            files.append('%s/authorized_keys' % ssh_path, key_text)

            run('chown -R %s:%s %s' % (username, username, ssh_path)) 
开发者ID:OpenConceptLab,项目名称:ocl_web,代码行数:31,代码来源:fabfile.py

示例14: common_install

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def common_install():
    """Basic one-time setup for common packages for ubuntu servers.

    Currently DB stuff and web stuff are listed together. Could split
    them if we run separate servers.
    """
    print yellow('common_install...')
    sudo('apt-get update')

    # user console tools
    sudo("apt-get -y -q install emacs23-nox unzip lsof byobu httpie")

    # application libraries
    sudo("apt-get -y -q  install python-pip git-core")
    sudo('apt-get -y -q install build-essential python-dev')
    sudo("apt-get -y -q  install libpq-dev")

    sudo("apt-get -y -q install supervisor")
    sudo("pip install virtualenv")

    # web
    # memcached
    sudo('apt-get -y -q install nginx')

    # database
    # if you don't want database, at least install the client
    # sudo("apt-get -y -q install postgresql-client")
    sudo("apt-get -y -q install postgresql postgresql-contrib")
    # Could use redis for celery but not yet
    # sudo("apt-get -q install redis-server") 
开发者ID:OpenConceptLab,项目名称:ocl_web,代码行数:32,代码来源:fabfile.py

示例15: setup_mongo

# 需要导入模块: from fabric import operations [as 别名]
# 或者: from fabric.operations import sudo [as 别名]
def setup_mongo():
    """ Setup mongo database """
    sudo('sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10')
    put(_conf_path('mongo.apt'), '/etc/apt/sources.list.d/mongodb.list', use_sudo=True)
    sudo('apt-get update')
    sudo('apt-get install -y -q mongodb-org') 
开发者ID:OpenConceptLab,项目名称:ocl_web,代码行数:8,代码来源:fabfile.py


注:本文中的fabric.operations.sudo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。