當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。