|
| 1 | +fromfabric.apiimporttask,settings,sudo,env,run |
| 2 | +fromfabric.tasksimportexecute |
| 3 | + |
| 4 | +importapp |
| 5 | +importnginx |
| 6 | +importpuppet |
| 7 | + |
| 8 | +@task |
| 9 | +defupdate_database(): |
| 10 | +"""Update a Mapit database using a new database dump""" |
| 11 | + |
| 12 | +iflen(env.hosts)>1: |
| 13 | +exit('This command should only be run on one Mapit machine at a time') |
| 14 | + |
| 15 | +execute(nginx.gracefulstop) |
| 16 | +execute(app.stop,'mapit') |
| 17 | +sudo('service collectd stop') |
| 18 | + |
| 19 | +sudo('rm /data/vhost/mapit/data/mapit.sql.gz') |
| 20 | + |
| 21 | +withsettings(sudo_user='postgres'): |
| 22 | +sudo("psql -c 'DROP DATABASE mapit;'") |
| 23 | + |
| 24 | +execute(puppet.agent,'--test') |
| 25 | + |
| 26 | + |
| 27 | +@task |
| 28 | +defcheck_database_upgrade(): |
| 29 | +"""Replay yesterday's Mapit requests to ensure that a database upgrade works""" |
| 30 | + |
| 31 | +sudo("awk '$9==200 {print\"http://localhost\" $7}' /var/log/nginx/mapit.access.log.1 > mapit-200s") |
| 32 | +sudo("awk '$9==404 {print\"http://localhost\" $7}' /var/log/nginx/mapit.access.log.1 > mapit-404s") |
| 33 | + |
| 34 | +print"Replaying Mapit 200s. Ensure that they are all still 200s." |
| 35 | +run('while read line; do curl -sI $line | grep HTTP/1.1 ; done < mapit-200s | sort | uniq -c') |
| 36 | +print"Replaying Mapit 404s. Ensure that they are all either 200s or 404s." |
| 37 | +run('while read line; do curl -sI $line | grep HTTP/1.1 ; done < mapit-404s | sort | uniq -c') |
| 38 | + |
| 39 | +sudo('rm ~/mapit-200s ~/mapit-404s') |