Skip to content

Commit f4db55d

Browse files
committed
Merge pull request alphagov#138 from alphagov/add-mapit-script
Add Mapit scripts
2 parents 216971c + b724a96 commit f4db55d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

fabfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import logstream
2727
import mongo
2828
import mainstream_slugs
29+
import mapit
2930
import mysql
3031
import nagios
3132
import nginx

mapit.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from fabric.api import task, settings, sudo, env, run
2+
from fabric.tasks import execute
3+
4+
import app
5+
import nginx
6+
import puppet
7+
8+
@task
9+
def update_database():
10+
"""Update a Mapit database using a new database dump"""
11+
12+
if len(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+
with settings(sudo_user='postgres'):
22+
sudo("psql -c 'DROP DATABASE mapit;'")
23+
24+
execute(puppet.agent, '--test')
25+
26+
27+
@task
28+
def check_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')

0 commit comments

Comments
 (0)