forked from alphagov/fabric-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.py
37 lines (30 loc) · 936 Bytes
/
nginx.py
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
from fabric.api import *
@task
def gracefulstop(wait=True):
"""Gracefully shutdown Nginx by finishing any in-flight requests"""
sudo('nginx -s quit')
if wait:
# Poll for Nginx, until it's no longer running.
run('while pgrep nginx >/dev/null; do echo "Waiting for Nginx to exit.."; sleep 1; done')
@task
def gracefulrestart():
"""Gracefully shutdown and start Nginx (not reload)"""
gracefulstop()
start()
@task
def disable_vhost(vhost_filename):
"""Disable a vhost by removing its symlink from /etc/nginx/sites-enabled"""
sudo('rm -f /etc/nginx/sites-enabled/%s' % vhost_filename)
@task
def kill():
"""Shut down Nginx immediately without waiting for it to finish running"""
sudo('service nginx stop')
@task
def start():
"""Start up Nginx on a machine"""
sudo('service nginx start')
@task
def hello_it():
"""Turns Nginx off and on again"""
kill()
start()