def start_letsencrypt_setup():
sudo("mkdir -p /tmp/git")
sudo("rm -rf /tmp/git/letsencrypt")
with cd("/tmp/git"):
sudo("git clone https://github.com/letsencrypt/letsencrypt")
with cd("/tmp/git/letsencrypt"):
sudo('./letsencrypt-auto certonly --standalone')
sudo('rm -rf /tmp/git')
python类cd()的实例源码
def run_setup_script(script_name, context):
venv_activate_path = os.path.join(VENV_BIN_DIRECTORY, 'activate')
venv_activate_command = 'source %s' % venv_activate_path
with cd(PROJECT_FOLDER), shell_env(**context), prefix(venv_activate_command):
run('python3 %s' % os.path.join(PROJECT_FOLDER, script_name))
def start_or_reload_service(has_started=False):
''' Start or reload the application service. '''
with cd(buildman.get_deploy_dir()):
if runner.is_script_defined(constants.SCRIPT_START_OR_RELOAD):
remote_info('Starting/Reloading the service.')
runner.run_script(constants.SCRIPT_START_OR_RELOAD)
elif has_started and runner.is_script_defined(constants.SCRIPT_RELOAD):
remote_info('Reloading the service.')
runner.run_script_safely(constants.SCRIPT_RELOAD)
elif runner.is_script_defined(constants.SCRIPT_START):
remote_info('Starting the service.')
runner.run_script(constants.SCRIPT_START)
def reload_service():
''' Restart the application service. '''
with cd(buildman.get_deploy_dir()):
remote_info('Reloading the service.')
runner.run_script_safely(constants.SCRIPT_RELOAD)
def stop_service():
''' Stop the application service. '''
with cd(buildman.get_deploy_dir()):
remote_info('Stopping the service.')
runner.run_script_safely(constants.SCRIPT_STOP)
def status():
''' Get the status of the service. '''
with cd(buildman.get_current_path()):
runner.run_script(constants.SCRIPT_STATUS_CHECK)
def services():
''' List the services running for the application. '''
with cd(buildman.get_current_path()):
runner.run_script(constants.SCRIPT_LIST_SERVICES)
def unlock():
"""os x servers need to be unlocked"""
require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)
with cd(env.path):
run('security unlock-keychain')
def makemigrations(app=None):
require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)
if env.srvr in ['dev', 'stg', 'liv']:
print(yellow('Do not run makemigrations on the servers'))
return
with cd(env.path), prefix(env.within_virtualenv):
run('./manage.py makemigrations {}'.format(app if app else ''))
def migrate(app=None):
require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)
with cd(env.path), prefix(env.within_virtualenv):
run('./manage.py migrate {}'.format(app if app else ''))
def update_index():
require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)
with cd(env.path), prefix(env.within_virtualenv):
run('./manage.py build_solr_schema > schema.xml')
run('mv schema.xml ../../solr/collection1/conf/')
sudo('service tomcat7-{} restart'.format(env.srvr))
run('./manage.py update_index')
def collect_static(process=False):
require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)
if env.srvr in ['local', 'vagrant']:
print(yellow('Do not run collect_static on local servers'))
return
with cd(env.path), prefix(env.within_virtualenv):
run('./manage.py collectstatic {process} --noinput'.format(
process=('--no-post-process' if not process else '')))
def install_requirements():
require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)
reqs = 'requirements-{}.txt'.format(env.srvr)
try:
assert os.path.exists(reqs)
except AssertionError:
reqs = 'requirements.txt'
with cd(env.path), prefix(env.within_virtualenv):
run('pip install -U -r {}'.format(reqs))
def reinstall_requirement(which):
require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)
with cd(env.path), prefix(env.within_virtualenv):
run('pip uninstall {0} && pip install --no-deps {0}'.format(which))
def touch_wsgi():
require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)
with cd(os.path.join(env.path, 'dprr')), prefix(env.within_virtualenv):
run('touch wsgi.py')
def runserver(port='8000'):
require('srvr', 'path', 'within_virtualenv', provided_by=env.servers)
if env.srvr not in ['local', 'vagrant']:
print(yellow('this server only runs for development purposes'))
return
with cd(env.path), prefix(env.within_virtualenv):
run('./manage.py runserver 0.0.0.0:{}'.format(port))
def manage_run(command, sudo=False):
"""Run a Django management command on the remote server."""
require('environment')
manage_base = u"%(virtualenv_root)s/bin/python %(code_root)s/manage.py " % env
with cd(env.code_root):
if sudo:
sudo(u'%s %s' % (manage_base, command))
else:
run(u'%s %s' % (manage_base, command))
def create_virtualenv():
with cd(PROJECT_DIR):
run('python3 -m venv venv')
def pull_repository():
with cd(PROJECT_DIR):
run('git pull origin master')