-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.py
99 lines (66 loc) · 1.71 KB
/
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
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
from fabric.api import require, sudo, task, env, put, run
from fabric.contrib import files
import utils
@task
def install():
"""
Install Nginx.
:Example:
fab --config=config.conf nginx.install
"""
sudo('apt-get -y install nginx')
@task
def restart():
"""
Restart the nginx service.
:Example:
fab --config=config.conf nginx.restart
"""
sudo('service nginx restart')
@task
def start():
"""
Start the nginx service.
:Example:
fab --config=config.conf nginx.start
"""
sudo('service nginx start')
@task
def stop():
"""
Stop the nginx service.
:Example:
fab --config=config.conf nginx.stop
"""
sudo('service nginx stop')
@task
def config():
"""
Upload a custom configuration file.
:Example:
fab --config=config.conf nginx.config
"""
local = utils.file_path('nginx', 'default')
remote = '/etc/nginx/sites-available/default'
target = '/etc/nginx/sites-enabled/default'
put(local, remote, mode='0644', use_sudo=True)
# Change owner to "root".
sudo('chown root:root {}'.format(remote))
# Remove old symlink.
sudo('rm {}'.format(target))
# Create new symlink.
sudo('ln -s {} {}'.format(remote, target))
# Create the nginx log directory.
run('mkdir -p {}'.format(utils.home('logs', 'nginx')))
@task
def public():
"""
Create the public directories.
:Example:
fab --config=config.conf nginx.public
"""
require('PROJECT_NAME')
media_dir = utils.home('public', env.PROJECT_NAME, 'media')
static_dir = utils.home('public', env.PROJECT_NAME, 'static')
run('mkdir -p {}'.format(media_dir))
run('mkdir -p {}'.format(static_dir))