Skip to content

Commit 8901499

Browse files
committed
Merge pull request alphagov#165 from alphagov/add_loadbalancer_maintenance_task
Add a task to put loadbalancers into maintenance
2 parents 5d24692 + 06c1b8a commit 8901499

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

nginx.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
from fabric.api import *
2+
import fabric.contrib.files
3+
import puppet
4+
5+
maintenance_config = '/etc/nginx/includes/maintenance.conf'
26

37
@task
8+
def enable_maintenance:
9+
"""Enables a maintenance page and serves a 503"""
10+
"""Only to be run on loadbalancers"""
11+
if not fabric.contrib.files.exists(maintenance_config):
12+
abort("Sorry this task can only currently be run on loadbalancers")
13+
puppet.disable("Maintenance mode enabled")
14+
sudo("echo 'set $maintenance 1;' > {0}".format(maintenance_config))
15+
sudo('service nginx reload')
16+
17+
def disable_maintenance:
18+
"""Disables a maintenance page"""
19+
"""Only to be run on loadbalancers"""
20+
if not fabric.contrib.files.exists(maintenance_config):
21+
abort("Sorry this task can only currently be run on loadbalancers")
22+
sudo("echo 'set $maintenance 0;' > {0}".format(maintenance_config))
23+
sudo('service nginx reload')
24+
puppet.enable()
25+
426
def gracefulstop(wait=True):
527
"""Gracefully shutdown Nginx by finishing any in-flight requests"""
628
sudo('nginx -s quit')

0 commit comments

Comments
 (0)