예제 #1
0
def run_export_media(filename=None):
    """
    Exports the media folder on the server.
    Usage::
        fab prod run_export_media
        fab prod run_export_media:filename=foobar.tar.gz
    """
    if not filename:
        filename = settings.MEDIA_DUMP_FILENAME

    with cd(settings.FAB_SETTING('SERVER_MEDIA_ROOT')):
        run('rm -rf {0}'.format(filename))
        run('tar -czf {0} *'.format(filename))
        run('mv {0} {1}'.format(
            filename, settings.FAB_SETTING('SERVER_MEDIA_BACKUP_DIR')))
예제 #2
0
def run_touch_wsgi():
    """
    Runs `touch <path>/wsgi.py` on the given server.
    Usage::
        fab <server> run_touch_wsgi
    """
    run('touch {0}'.format(settings.FAB_SETTING('SERVER_WSGI_FILE')))
예제 #3
0
def run_rsync_project():
    """
    Copies the project from the git repository to it's destination folder.
    This has the nice side effect of rsync deleting all ``.pyc`` files and
    removing other files that might have been left behind by sys admins messing
    around on the server.
    Usage::
        fab <server> run_rsync_project
    """
    excludes = ''
    for exclude in settings.RSYNC_EXCLUDES:
        excludes += " --exclude '{0}'".format(exclude)
    command = "rsync -avz --stats --delete {0} {1} {2}".format(
        excludes, settings.FAB_SETTING('SERVER_REPO_PROJECT_ROOT'),
        settings.FAB_SETTING('SERVER_APP_ROOT'))
    run(command)
예제 #4
0
def run_restart_apache():
    """
    Restarts apache on the given server.
    Usage::
        fab <server> run_restart_apache
    """
    run('{0}restart'.format(settings.FAB_SETTING('SERVER_APACHE_BIN_DIR')))
예제 #5
0
def export_db(filename=None, remote=False):
    """
    Exports the database.

    Make sure that you have this in your ``~/.pgpass`` file:

    localhost:5433:*:<db_role>:<password>

    Also make sure that the file has ``chmod 0600 .pgpass``.

    Usage::

        fab export_db
        fab export_db:filename=foobar.dump

    """
    local_machine()
    if not filename:
        filename = settings.DB_DUMP_FILENAME
    if remote:
        backup_dir = settings.FAB_SETTING('SERVER_DB_BACKUP_DIR')
    else:
        backup_dir = ''

    local('pg_dump -c -Fc -O -U {0}{1} {2} -f {3}{4}'.format(
        env.db_role, HOST, env.db_name, backup_dir, filename))
예제 #6
0
def run_git_pull():
    """
    Pulls the latest code and updates submodules.
    Usage::
        fab <server> run_git_pull
    """
    with cd(settings.FAB_SETTING('SERVER_REPO_ROOT')):
        run('git pull && git submodule init && git submodule update')
예제 #7
0
def run_compilemessages():
    """
    Executes ./manage.py compilemessages on the server.
    Usage::
        fab <server name> run_compilemessages
    """

    with cd(settings.FAB_SETTING('SERVER_PROJECT_ROOT')):
        run_workon('python{} manage.py compilemessages'.format(PYTHON_VERSION))
예제 #8
0
def run_restart_nginx():
    """
    Restarts uwsgi on the given server.
    Usage::
        fab <server> run_restart_nginx
    """

    with cd(settings.FAB_SETTING('SERVER_LOCAL_ETC_DIR')):
        run('supervisorctl restart nginx')
예제 #9
0
def run_collectstatic():
    """
    Runs `./manage.py collectstatic` on the given server.
    Usage::
        fab <server> run_collectstatic
    """
    with cd(settings.FAB_SETTING('SERVER_PROJECT_ROOT')):
        run_workon('python{} manage.py collectstatic --noinput'.format(
            PYTHON_VERSION))
예제 #10
0
def run_update_presentations():
    """
    Runs `./manage.py update_presentations` on the given server.

    Usage::

        fab <server> run_update_presentations

    """
    with cd(settings.FAB_SETTING('SERVER_PROJECT_ROOT')):
        run_workon('python2.7 manage.py update_presentations')
예제 #11
0
def run_export_db(filename=None):
    """
    Exports the database on the server.
    Usage::
        fab prod run_export_db
        fab prod run_export_db:filename=foobar.dump
    """
    if not filename:
        filename = settings.DB_DUMP_FILENAME
    with cd(settings.FAB_SETTING('SERVER_PROJECT_ROOT')):
        run_workon('fab export_db:remote=True,filename={}'.format(filename))
예제 #12
0
def run_syncdb():
    """
    Runs `./manage.py syncdb --migrate` on the given server.
    Usage::
        fab <server> run_syncdb
    """
    with cd(settings.FAB_SETTING('SERVER_PROJECT_ROOT')):
        if StrictVersion(django.get_version()) < StrictVersion('1.7'):
            run_workon('python{} manage.py syncdb --migrate --noinput'.format(
                PYTHON_VERSION))
        else:
            run_workon('python{} manage.py migrate'.format(PYTHON_VERSION))
예제 #13
0
def run_pip_install(upgrade=0):
    """
    Installs the requirement.txt file on the given server.
    Usage::
        fab <server> run_pip_install
        fab <server> run_pip_install:upgrade=1
    :param upgrade: If set to 1, the command will be executed with the
      ``--upgrade`` flag.
    """
    command = 'pip install -r {0}'.format(
        settings.FAB_SETTING('SERVER_REQUIREMENTS_PATH'))
    if upgrade:
        command += ' --upgrade'
    run_workon(command)
예제 #14
0
def run_download_media(filename=None):
    """
    Downloads the media dump from the server into your local machine.
    In order to import the downloaded media dump, run ``fab import_media``
    Usage::
        fab prod run_download_media
        fab prod run_download_media:filename=foobar.tar.gz
    """
    if not filename:
        filename = settings.MEDIA_DUMP_FILENAME
    if env.key_filename:
        ssh = settings.PROJECT_NAME
    else:
        ssh = '{0}@{1}'.format(env.user, env.host_string)
    local('scp {0}:{1}{2} .'.format(
        ssh, settings.FAB_SETTING('SERVER_MEDIA_BACKUP_DIR'), filename))
예제 #15
0
def run_download_db(filename=None):
    """
    Downloads the database from the server into your local machine.
    In order to import the downloaded database, run ``fab import_db``
    Usage::
        fab prod run_download_db
        fab prod run_download_db:filename=foobar.dump
    """
    if not filename:
        filename = settings.DB_DUMP_FILENAME
    if env.key_filename:
        ssh = settings.PROJECT_NAME
    else:
        ssh = '{0}@{1}'.format(env.user, env.host_string)
    local('scp {0}:{1}{2} .'.format(
        ssh, settings.FAB_SETTING('SERVER_DB_BACKUP_DIR'), filename))
예제 #16
0
def run_upload_db(filename=None):
    """
    Uploads your local database to the server.
    You can create a local dump with ``fab export_db`` first.
    In order to import the database on the server you still need to SSH into
    the server.
    Usage::
        fab prod run_upload_db
        fab prod run_upload_db:filename=foobar.dump
    """
    if not filename:
        filename = settings.DB_DUMP_FILENAME
    if env.key_filename:
        ssh = settings.PROJECT_NAME
    else:
        ssh = '{0}@{1}'.format(env.user, env.host_string)
    local('scp {0} {1}:{3}'.format(
        filename, ssh, settings.FAB_SETTING('SERVER_DB_BACKUP_DIR')))