From 0b5f6234add4b1d8b470f3a4c241c191109e8bf6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 30 Sep 2019 15:37:21 -0500 Subject: [PATCH] Add upgrade, restart-overnight-backups scripts for generic backup app --- rattail_fabric2/backup.py | 14 ++++++++++- .../deploy/backup/backup-everything.mako | 19 +++----------- .../backup/restart-overnight-backups.sh.mako | 5 ++++ rattail_fabric2/deploy/backup/upgrade.sh.mako | 25 +++++++++++++++++++ 4 files changed, 46 insertions(+), 17 deletions(-) create mode 100755 rattail_fabric2/deploy/backup/restart-overnight-backups.sh.mako create mode 100755 rattail_fabric2/deploy/backup/upgrade.sh.mako diff --git a/rattail_fabric2/backup.py b/rattail_fabric2/backup.py index a3d798f..7b8601b 100644 --- a/rattail_fabric2/backup.py +++ b/rattail_fabric2/backup.py @@ -104,7 +104,7 @@ def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail', # config c.sudo("bash -l -c 'workon {} && cdvirtualenv && rattail make-appdir'".format(envname), user=user) # note, config is owned by root regardless of `user` - since we always run backups as root - deploy(c, config, os.path.join(envpath, 'app/rattail.conf'), owner='root', mode='0600', use_sudo=True, context=context) + deploy(c, config, os.path.join(envpath, 'app/rattail.conf'), owner='root:{}'.format(user), mode='0640', use_sudo=True, context=context) c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/rattail -c app/rattail.conf make-config -T quiet -O app/'".format(envname), user=user) c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/rattail -c app/rattail.conf make-config -T silent -O app/'".format(envname), user=user) @@ -156,6 +156,9 @@ def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail', deploy_generic(c, 'backup/luigi-logging.conf.mako', '{}/app/luigi/luigi-logging.conf'.format(envpath), owner=user, use_sudo=True, context={'envpath': envpath}) + # needed for restarting luigi tasks + apt.install(c, 'at') + # app/luigitasks/overnight.py - should define the OvernightBackups wrapper task path = '{}/luigi-overnight.py'.format(envname) if deploy.local_exists(path): @@ -169,6 +172,10 @@ def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail', deploy_generic(c, 'backup/overnight-backups.sh.mako', '{}/app/overnight-backups.sh'.format(envpath), owner=user, mode='0755', use_sudo=True, context={'envpath': envpath}) + # app/restart-overnight-backups.sh - generic script to restart OvernightBackups task + deploy_generic(c, 'backup/restart-overnight-backups.sh.mako', '{}/app/restart-overnight-backups.sh'.format(envpath), + owner=user, mode='0755', use_sudo=True, context={'envpath': envpath}) + # supervisor / luigid apt.install(c, 'supervisor') deploy_generic(c, 'backup/supervisor.conf.mako', '/etc/supervisor/conf.d/backup.conf', @@ -178,6 +185,11 @@ def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail', c.sudo('supervisorctl update') c.sudo('supervisorctl start backup:') + # upgrade script + if install_rattail: + deploy_generic(c, 'backup/upgrade.sh.mako', '{}/app/upgrade.sh'.format(envpath), + owner=user, mode='0755', use_sudo=True, context={'envpath': envpath, 'user': user}) + # backup-everything script if install_rattail or everything: everything_context = dict(context) diff --git a/rattail_fabric2/deploy/backup/backup-everything.mako b/rattail_fabric2/deploy/backup/backup-everything.mako index 63d600a..62a0f11 100755 --- a/rattail_fabric2/deploy/backup/backup-everything.mako +++ b/rattail_fabric2/deploy/backup/backup-everything.mako @@ -2,19 +2,16 @@ if [ "$1" = "-v" -o "$1" = "--verbose" ]; then VERBOSE='--verbose' - QUIET= PROGRESS='--progress' CONFIG='/srv/envs/${envname}/app/rattail.conf' else VERBOSE= - QUIET='--quiet' PROGRESS= CONFIG='/srv/envs/${envname}/app/silent.conf' fi - RATTAIL="/srv/envs/${envname}/bin/rattail --config=$CONFIG $PROGRESS $VERBOSE" -PIP="sudo -H -u ${user} PIP_CONFIG_FILE=/srv/envs/${envname}/pip.conf /srv/envs/${envname}/bin/pip" + # sanity check if [ "$HOME" != '/root' ]; then @@ -25,18 +22,8 @@ if [ "$HOME" != '/root' ]; then exit 1 fi -# upgrade pip -$PIP install $QUIET --upgrade pip - -# upgrade rattail -cd /srv/envs/${envname}/src/rattail -if [ "$(sudo -H -u ${user} git status --porcelain)" != '' ]; then - sudo -H -u ${user} git status - exit 1 -fi -sudo -H -u ${user} git pull $QUIET -find . -name '*.pyc' -delete -$PIP install $QUIET --upgrade --upgrade-strategy eager --editable . +# upgrade app +/srv/envs/${envname}/app/upgrade.sh $VERBOSE # run backup cd /srv/envs/${envname} diff --git a/rattail_fabric2/deploy/backup/restart-overnight-backups.sh.mako b/rattail_fabric2/deploy/backup/restart-overnight-backups.sh.mako new file mode 100755 index 0000000..ff7879a --- /dev/null +++ b/rattail_fabric2/deploy/backup/restart-overnight-backups.sh.mako @@ -0,0 +1,5 @@ +#!/bin/sh -e + +DATE=`date --date='yesterday' +%Y-%m-%d` + +echo "${envpath}/bin/rattail -c ${envpath}/app/silent.conf --no-versioning run-n-mail -S 'Backups (continued)' '${envpath}/app/overnight-backups.sh $DATE'" | at 'now + 1 minute' diff --git a/rattail_fabric2/deploy/backup/upgrade.sh.mako b/rattail_fabric2/deploy/backup/upgrade.sh.mako new file mode 100755 index 0000000..b551a09 --- /dev/null +++ b/rattail_fabric2/deploy/backup/upgrade.sh.mako @@ -0,0 +1,25 @@ +#!/bin/sh -e + +if [ "$1" = "-v" -o "$1" = "--verbose" ]; then + VERBOSE='--verbose' + QUIET= +else + VERBOSE= + QUIET='--quiet' +fi + +PIP="sudo -H -u ${user} PIP_CONFIG_FILE=${envpath}/pip.conf ${envpath}/bin/pip" + + +# upgrade pip +$PIP install $QUIET --upgrade pip + +# upgrade rattail +cd ${envpath}/src/rattail +if [ "$(sudo -H -u ${user} git status --porcelain)" != '' ]; then + sudo -H -u ${user} git status + exit 1 +fi +sudo -H -u ${user} git pull $QUIET +find . -name '*.pyc' -delete +$PIP install $QUIET --upgrade --upgrade-strategy eager --editable .