Changeset 2fcb81e in rattail-fabric


Ignore:
Timestamp:
07/05/18 13:19:20 (2 years ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
d519db6
Parents:
2a6b252
Message:

Allow more customization for backup app deployment

Location:
rattail_fabric
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • rattail_fabric/__init__.py

    r2a6b252 r2fcb81e  
    3030from __future__ import unicode_literals, absolute_import
    3131
    32 from .core import put, upload_template, make_deploy, mkdir, rsync
     32from .core import put, upload_template, make_deploy, mkdir, rsync, UNSPECIFIED
    3333from .core import make_system_user, set_timezone, agent_sudo
    3434from .core import get_debian_version, get_ubuntu_version
  • rattail_fabric/backup.py

    r2a6b252 r2fcb81e  
    3232from fabric.contrib.files import exists
    3333
    34 from rattail_fabric import make_deploy, mkdir, python
     34from rattail_fabric import make_deploy, mkdir, python, UNSPECIFIED
    3535
    3636
     
    3838
    3939
    40 def deploy_backup_app(deploy, envname, config=None, everything=None, crontab=None, user='rattail', runat=None):
     40def deploy_backup_everything(**context):
     41    """
     42    Deploy the generic `backup-everything` script
     43    """
     44    context.setdefault('envname', 'backup')
     45    context.setdefault('user', 'rattail')
     46    deploy_generic('backup/backup-everything.mako', '/usr/local/bin/backup-everything', mode='0755',
     47                   context=context)
     48
     49
     50def deploy_backup_app(deploy, envname, mkvirtualenv=True, user='rattail',
     51                      config=None, everything=None, crontab=None, runat=UNSPECIFIED):
    4152    """
    4253    Make an app which can run backups for the server.
     
    4960            raise ValueError("Must provide config path for backup app")
    5061
    51     if not runat:
     62    if runat is UNSPECIFIED:
    5263        runat = datetime.time(0) # defaults to midnight
    5364
    5465    # virtualenv
    55     python.mkvirtualenv(envname, python='/usr/bin/python3', upgrade_setuptools=False)
     66    if mkvirtualenv:
     67        python.mkvirtualenv(envname, python='/usr/bin/python3', upgrade_setuptools=False)
    5668    envpath = '/srv/envs/{}'.format(envname)
    5769    sudo('chown -R {}: {}'.format(user, envpath))
     
    7789
    7890    # backup-everything script
    79     everything_context = {'envname': envname}
     91    everything_context = {
     92        'envname': envname,
     93        'user': user,
     94    }
    8095    if everything:
    8196        deploy(everything, '/usr/local/bin/backup-everything', mode='0755', context=everything_context)
    8297    else:
    83         deploy_generic('backup/backup-everything.mako', '/usr/local/bin/backup-everything', mode='0755',
    84                        context=everything_context)
     98        deploy_backup_everything(**everything_context)
    8599
    86100    # crontab
    87     crontab_context = {
    88         'envname': envname,
    89         'pretty_time': runat.strftime('%I:%M %p'),
    90         'cron_time': runat.strftime('%M %H'),
    91     }
    92     if crontab:
    93         deploy(crontab, '/etc/cron.d/backup', context=crontab_context)
    94     else:
    95         deploy_generic('backup/crontab.mako', '/etc/cron.d/backup', context=crontab_context)
     101    if runat:
     102        crontab_context = {
     103            'envname': envname,
     104            'pretty_time': runat.strftime('%I:%M %p'),
     105            'cron_time': runat.strftime('%M %H'),
     106        }
     107        if crontab:
     108            deploy(crontab, '/etc/cron.d/backup', context=crontab_context)
     109        else:
     110            deploy_generic('backup/crontab.mako', '/etc/cron.d/backup', context=crontab_context)
  • rattail_fabric/core.py

    r2a6b252 r2fcb81e  
    3737
    3838from mako.template import Template
     39
     40
     41UNSPECIFIED = object()
    3942
    4043
  • rattail_fabric/deploy/backup/backup-everything.mako

    r2a6b252 r2fcb81e  
    33if [ "$1" = "-v" -o "$1" = "--verbose" ]; then
    44    VERBOSE='--verbose'
     5    QUIET=
    56    PROGRESS='--progress'
    67    CONFIG='app/rattail.conf'
    78else
    89    VERBOSE=
     10    QUIET='--quiet'
    911    PROGRESS=
    1012    CONFIG='app/silent.conf'
     
    1517
    1618RATTAIL="bin/rattail --config=$CONFIG $PROGRESS"
     19PIP='bin/pip'
     20export PIP_CONFIG_FILE=pip.conf
     21
     22$PIP install --upgrade pip
     23
     24cd src/rattail
     25sudo -u ${user} git pull $QUIET
     26sudo -u ${user} find . -name '*.pyc' -delete
     27cd -
     28$PIP install --upgrade --upgrade-strategy eager --editable src/rattail
    1729
    1830$RATTAIL backup
Note: See TracChangeset for help on using the changeset viewer.