-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeb_dja_vew.py
113 lines (90 loc) · 2.62 KB
/
deb_dja_vew.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""
Sample of a server with Debian + Django + virtualenvwrapper + supervisor.
"""
from fabric.api import run, cd, prefix, settings, sudo
CLONE_PATH = "{path/to/your/project}"
PROJECT_PATH = "{Your project path}"
VIRTUAL_ENV_NAME = "{your virtualenv name}"
GIT_REPO = "{your repository here}"
REQUIRE_PATH_LIST = [
"list",
"of",
"path",
"requirements"
]
MASTER_USER = "Other master user root here"
MASTER_PASSWORD = "Other master password root here"
SUPERVISOR_APPS = ["one app", "another app"]
def install_git_pip():
"""
Install git, pip and dependencies
- Debian Like
"""
run("sudo apt-get install git; git-core; python-pip")
def clone_project():
"""
Clone project to folder
"""
with cd(CLONE_PATH):
with prefix("workon {}".format(VIRTUAL_ENV_NAME)):
run("git clone {}".format(GIT_REPO))
def pull_project(branch="master"):
"""
Pull git project
"""
with cd(PROJECT_PATH):
run("git pull origin {}".format(branch))
def collect_static():
"""
Django collectstatic
"""
with cd(PROJECT_PATH):
with prefix("workon {}".format(VIRTUAL_ENV_NAME)):
run("python manage.py collectstatic --noinput")
def full_deploy():
"""
Make a full Deploy of project
"""
pull_project("master")
install_requirements()
manage('migrate --all')
collect_static()
service_restart("{your service here}")
restart_apps()
def run_sudo_master(command="ll"):
"""
Example to execute a command with another Root user if needed
"""
with settings(user=MASTER_USER, password=MASTER_PASSWORD):
run(command)
def service_restart(app_name="nginx"):
"""
Restart a service
- if an app not started yet, restart will
"""
run("sudo service {} restart".format(app_name))
def restart_apps(app=False):
"""
If not pass an app, he takes all apps on SUPERVISOR_APPS var
Like service_restart will started all apps that not started yet
"""
if app:
sudo("sudo supervisorctl restart {}".format(app))
else:
for app in SUPERVISOR_APPS:
sudo("sudo supervisorctl restart {}".format(app))
def manage(args):
"""
Alias for django project manage
"""
with cd(PROJECT_PATH):
with prefix("workon {}".format(VIRTUAL_ENV_NAME)):
run("python manage.py {}".format(args))
def install_requirements():
"""
Install requirements based on REQUIRE_PATH_LIST
"""
for path in REQUIRE_PATH_LIST:
with cd(path):
with prefix("workon {}".format(VIRTUAL_ENV_NAME)):
run("pip install -r requirements.txt")