本文整理匯總了Python中fabric.api.sudo方法的典型用法代碼示例。如果您正苦於以下問題:Python api.sudo方法的具體用法?Python api.sudo怎麽用?Python api.sudo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類fabric.api
的用法示例。
在下文中一共展示了api.sudo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: update
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def update():
"""Update the svn repo, then reinstall LNT."""
with cd(LNT_PATH):
with cd(LNT_PATH + "/docs/"):
sudo('rm -rf _build')
with cd(LNT_PATH + "/lnt/server/ui/static"):
sudo('rm -rf docs')
sudo('git checkout docs')
sudo("git pull --rebase")
run("git log -1 --pretty=%B")
with cd(LNT_PATH + "/docs/"):
sudo(in_venv("make"))
sudo(IN_VENV + "python setup.py install --server")
put(here + "/blacklist", "/tmp/blacklist")
sudo("mv /tmp/blacklist /srv/lnt/install/blacklist")
put(here + "/kill_zombies.py", "/tmp/kill_zombies.py")
sudo("mv /tmp/kill_zombies.py /etc/cron.hourly/kill_zombies")
sudo("chmod +x /etc/cron.hourly/kill_zombies")
rotate_log()
service_restart()
示例2: setup_supervisor
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def setup_supervisor():
# We use supervisord to keep Crestify running in the background
# Recover from crashes, and to start automatically on bootup
# Also, using more than 1 gunicorn worker resulted in socket not being released, so only 1 worker will be used
sudo('apt-get -y install supervisor')
sudo('mkdir /var/log/crestify/')
sudo(
'cd /home/crestify/crestify && ../crestifyenv/bin/honcho export -s /bin/sh -a crestify supervisord /etc/supervisor/conf.d')
fd = StringIO()
get('/etc/supervisor/conf.d/crestify.conf', fd)
content = fd.getvalue().splitlines()
for n, i in enumerate(content):
if i.startswith("environment="):
content[n] = i + ",PATH=/home/crestify/crestifyenv/bin:%(ENV_PATH)s"
if i.startswith("user="):
content[n] = "user=crestify"
if i.startswith("stopsignal="):
content[n] = "stopsignal=TERM" # Both Gunicorn and Celery use SIGTERM for graceful shutdown
content = StringIO("\n".join(content))
put(content, "/etc/supervisor/conf.d/crestify.conf", use_sudo=True)
sudo('supervisorctl reread')
sudo('supervisorctl update')
示例3: install_required_packages
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def install_required_packages():
sudo("apt-get update -y")
sudo("apt-get install -y git")
sudo("apt-get install -y wget")
sudo("apt-get install -y python2.7-dev")
sudo("apt-get install -y python-pip")
sudo("apt-get install -y ipython")
sudo("apt-get install -y libffi-dev")
sudo("apt-get install -y libssl-dev")
sudo("apt-get install -y libxml2-dev")
sudo("apt-get install -y libxslt1-dev")
sudo("apt-get install -y libpng12-dev")
sudo("apt-get install -y libfreetype6-dev")
sudo("apt-get install -y python-tk")
sudo("apt-get install -y libsasl2-dev")
sudo("apt-get install -y python-pip")
sudo("apt-get install -y graphviz")
sudo("pip install --upgrade pip")
示例4: run_command
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def run_command(self, hosts, parallel_pool_size=1):
from fabric.api import execute, sudo, env, parallel
if env.ssh_config_path and os.path.isfile(os.path.expanduser(env.ssh_config_path)):
env.use_ssh_config = True
env.forward_agent = True
# pass `-E` to sudo to preserve environment for ssh agent forwarding
env.sudo_prefix = "sudo -SE -p '%(sudo_prompt)s' "
env.user = self.user_name
env.password = self.password
env.hosts = hosts
env.warn_only = True
def _task():
result = sudo(self.command, user=self.user_as)
return result
task = _task
if parallel_pool_size > 1:
task = parallel(pool_size=parallel_pool_size)(_task)
res = execute(task)
return res
示例5: rollback_formplayer
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def rollback_formplayer():
build_dir = os.path.join(env.code_current, FORMPLAYER_BUILD_DIR)
builds = _get_old_formplayer_builds(build_dir)
if not builds:
utils.abort('No formplayer builds to rollback to.')
rollback_build = builds[0]
if not console.confirm('Confirm rollback to "{}"'.format(rollback_build), default=False):
utils.abort('Action aborted.')
with cd(build_dir):
sudo('ln -sfn {build_dir}/{rollback} {build_dir}/current'.format(
build_dir=build_dir,
rollback=rollback_build
))
示例6: update_code
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def update_code(full_cluster=True):
roles_to_use = _get_roles(full_cluster)
@roles(roles_to_use)
@parallel
def update(git_tag, use_current_release=False):
# If not updating current release, we are making a new release and thus have to do cloning
# we should only ever not make a new release when doing a hotfix deploy
if not use_current_release:
_update_code_from_previous_release()
with cd(env.code_root if not use_current_release else env.code_current):
sudo('git remote prune origin')
# this can get into a state where running it once fails
# but primes it to succeed the next time it runs
sudo('git fetch origin --tags -q || git fetch origin --tags -q')
sudo('git checkout {}'.format(git_tag))
sudo('git reset --hard {}'.format(git_tag))
sudo('git submodule sync')
sudo('git submodule update --init --recursive -q')
# remove all untracked files, including submodules
sudo("git clean -ffd")
# remove all .pyc files in the project
sudo("find . -name '*.pyc' -delete")
return update
示例7: _clone_code_from_local_path
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def _clone_code_from_local_path(from_path, to_path, run_as_sudo=True):
cmd_fn = sudo if run_as_sudo else run
git_local_submodule_config = [
'git config {} {}'.format(submodule_config.key, submodule_config.value)
for submodule_config in _get_local_submodule_urls(from_path)
]
git_remote_submodule_config = [
'git config {} {}'.format(submodule_config.key, submodule_config.value)
for submodule_config in _get_remote_submodule_urls(from_path)
]
with cd(from_path):
cmd_fn('git clone {}/.git {}'.format(
from_path,
to_path
))
with cd(to_path):
cmd_fn('git config receive.denyCurrentBranch updateInstead')
cmd_fn(' && '.join(git_local_submodule_config))
cmd_fn('git submodule update --init --recursive')
cmd_fn(' && '.join(git_remote_submodule_config))
示例8: record_successful_deploy
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def record_successful_deploy():
start_time = datetime.strptime(env.deploy_metadata.timestamp, DATE_FMT)
delta = datetime.utcnow() - start_time
with cd(env.code_current):
env.deploy_metadata.tag_commit()
sudo((
'%(virtualenv_current)s/bin/python manage.py '
'record_deploy_success --user "%(user)s" --environment '
'"%(environment)s" --url %(url)s --minutes %(minutes)s --mail_admins'
) % {
'virtualenv_current': env.py3_virtualenv_current,
'user': env.user,
'environment': env.deploy_env,
'url': env.deploy_metadata.diff_url,
'minutes': str(int(delta.total_seconds() // 60))
})
示例9: ensure_checkpoints_safe
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def ensure_checkpoints_safe():
extras = '--print-only' if env.ignore_kafka_checkpoint_warning else ''
with cd(env.code_root):
try:
sudo('{env.py3_virtualenv_root}/bin/python manage.py validate_kafka_pillow_checkpoints {extras}'.format(
env=env, extras=extras
))
except Exception as e:
if not env.ignore_kafka_checkpoint_warning:
message = (
"Deploy failed, likely because kafka checkpoints weren't available.\n"
"Scroll up for more detailed information.\n"
"You can rerun with --set ignore_kafka_checkpoint_warning=true to prevent this error from blocking the deploy."
).format(e)
raise Exception(message)
else:
# if we were forcing and still got an error this is likely a bug so we should raise it
raise
示例10: deploy
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def deploy(self):
self.config = self.read_config(self.directory)
if "host" not in self.config:
raise Exception("Missing required field in rorolite.yml: host")
self.version = self.find_current_version() + 1
self.deploy_root = "/opt/rorolite/deploys/{}".format(self.version)
print("Deploying project version {}...".format(self.version))
remote.sudo("mkdir -p " + self.deploy_root)
self.push_directory()
self.setup_virtualenv()
remote.sudo("ln -sfT {} /opt/rorolite/project".format(self.deploy_root))
self.restart_services()
示例11: restart_services
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def restart_services(self):
services = self.config.get('services', [])
# TODO: validate services
sudo("rm -rf /etc/supervisor/conf.d && ln -sfT /opt/rorolite/project/.rorolite/supervisor /etc/supervisor/conf.d")
sudo("supervisorctl update")
if not services:
print("Deploy successful. No services found.")
return
for s in services:
sudo("supervisorctl restart {}".format(s['name']))
host = self.config['host']
print("Services are live at:")
for s in services:
print(" {} -- http://{}:{}/".format(s['name'], host, s['port']))
示例12: ps
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def ps():
sudo('ps auxxxf | grep gunicorn')
示例13: rotate_log
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def rotate_log():
"""Rotate the LNT log."""
sudo('rm -rf /srv/lnt/install/gunicorn.error.log')
out = sudo('ps auxxxf | grep "gunicorn: master"')
pid = re.search(r'lnt\s+(?P<pid>\d+)\s+', out).groupdict()['pid']
print pid
sudo('kill -USR1 ' + pid)
示例14: df
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def df():
sudo('df -h')
示例15: kill_zombies
# 需要導入模塊: from fabric import api [as 別名]
# 或者: from fabric.api import sudo [as 別名]
def kill_zombies():
import re
out = sudo("ps auxxxf")
stranded = re.compile(r"^lnt\s+(?P<pid>\d+).*00\sgunicorn:\swork")
pids = []
for line in out.split('\n'):
m = stranded.match(line)
if m:
pid = m.groupdict()['pid']
pids.append(pid)
else:
print ">", line
for pid in pids:
sudo("kill -9 {}".format(pid))