forked from metabrainz/musicbrainz-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfabfile.py
More file actions
134 lines (107 loc) · 4.5 KB
/
Copy pathfabfile.py
File metadata and controls
134 lines (107 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from fabric.api import *
from time import sleep
from fabric.colors import red
env.use_ssh_config = True
env.sudo_prefix = "sudo -S -p '%(sudo_prompt)s' -H " % env
def socket_deploy():
"""
Do a Unix FastCGI socket deployment of musicbrainz-server. This works by
restarting the process and taking down the old one if a new process could
successful be started.
"""
with cd("~/musicbrainz-server"):
run("git pull --ff-only")
run("~/musicbrainz-server/admin/socket-deploy.sh")
def no_local_changes():
# The exit code of these will be 0 if there are no changes.
# If there are changes, then the author should fix his damn code.
with settings( hide("stdout") ):
local("git diff --exit-code")
local("git diff --exit-code --cached")
def beta():
"""
Update the beta.musicbrainz.org server
This requires you have a 'beta' alias in your .ssh/config file.
"""
env.host_string = "beta"
no_local_changes()
with settings( hide("stdout", "stderr") ):
local("git checkout beta")
local("git merge master")
local("git push origin beta")
socket_deploy()
def test():
"""
Update the test.musicbrainz.org server
This requires you have a 'test' alias in your .ssh/config file.
"""
env.host_string = "test"
no_local_changes()
with settings( hide("stdout", "stderr") ):
local("git checkout test")
local("git merge master")
local("git push origin test")
socket_deploy()
def production():
"""
To upgrade the servers, first take them out of the load balancer one by
one. Then, use Fabric to update them:
fab production
You will be prompted to check you wish to continue, and then prompted for a
server to update. The Fabric deployment script will take care of taking the
service down, running a Git pull (and running the rest of
production-deploy.sh) and then bring the service back up.
It will attempt to check that the server started correctly by looking at the
tail of the log and also doing a curl against localhost.
"""
puts("Checking if the server is quiet (expecting no requests in 5 second window)")
with settings( hide("stdout") ):
t1 = run("tail /var/log/nginx/001-musicbrainz.access.log")
sleep(5)
t2 = run("tail /var/log/nginx/001-musicbrainz.access.log")
if t1 != t2:
puts(red("The server does NOT appear to be quiet!"))
cont = prompt("Do you wish to proceed?", validate=r'^(yes|no)', default='no')
if cont == 'no':
abort('User does not wish to proceed')
with cd('/home/musicbrainz/musicbrainz-server'):
# Carton has a tendency to change this file when it does update
# It's important that we discard these
sudo("git reset HEAD -- carton.lock", user="musicbrainz")
sudo("git checkout -- carton.lock", user="musicbrainz")
# If there's anything uncommited this must be fixed
sudo("git diff --exit-code", user="musicbrainz")
sudo("git diff --exit-code --cached", user="musicbrainz")
old_rev = sudo("git rev-parse HEAD", user="musicbrainz")
sudo("git pull --ff-only", user="musicbrainz")
new_rev = sudo("git rev-parse HEAD", user="musicbrainz")
sql_updates = sudo("git diff --name-only %s %s -- admin/sql/updates" % (old_rev, new_rev), user="musicbrainz")
if sql_updates != '':
puts("Remember to update the following files:")
puts(sql_updates)
shutdown()
sudo("/home/musicbrainz/musicbrainz-server/admin/production-deploy.sh", user="musicbrainz")
sudo("svc -u /etc/service/mb_server-fastcgi")
puts("Waiting 20 seconds for server to start")
sleep(20)
sudo("/etc/init.d/nginx restart", pty=False)
# A non-0 exit code from any of these will cause the deployment to abort
with settings( hide("stdout") ):
run("pgrep plackup")
run("tail /etc/service/mb_server-fastcgi/log/main/current | grep started")
run("wget http://localhost -O -")
def reset_test():
"""
Reset the 'test' branch, and do a socket update release
"""
no_local_changes()
local("git checkout test")
local("git reset --hard origin/beta")
local("git push --force origin test")
with settings(host_string='test'):
with cd("/home/musicbrainz/musicbrainz-server"):
run("git fetch")
run("git reset --hard origin/test")
socket_deploy()
def shutdown():
sudo("svc -d /etc/service/mb_server-fastcgi")