-
Notifications
You must be signed in to change notification settings - Fork 26
/
fabfile.py
99 lines (68 loc) · 2.22 KB
/
fabfile.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
# coding: utf-8
from contextlib import contextmanager
from fabric.api import cd, env, local, run, sudo, prefix
try:
from fabenv import env
except ImportError:
msg = "Kurulum için lütfen README.md belgesini okuyun."
raise RuntimeError(msg)
@contextmanager
def venv():
with cd('%(root)s%(project_name)s' % env), prefix(env.activate):
yield
def deploy():
"""Deploy the latest version."""
with venv():
run('git pull')
update_dependencies()
run('python manage.py migrate')
update_static()
restart()
restart_nginx()
def start():
with venv():
run('gunicorn -c conf/gunicorn.py pyist.wsgi:application')
restart_nginx()
def restart():
with venv():
sudo('sudo kill -HUP `cat /tmp/' + env.project_name + '.pid`')
def restart_nginx():
"""Restart the nginx process."""
sudo('/etc/init.d/nginx restart')
def update_dependencies():
"""Update requirements remotely."""
with venv():
run('pip install -r conf/requirements.txt')
def update_nginx_conf():
sudo('rm /etc/nginx/sites-enabled/' + env.domain)
sudo('ln -s /home/wakefield/pyistanbul/conf/nginx.conf /etc/nginx/sites-enabled/' + env.domain)
restart_nginx()
def update_static():
"""Update static files."""
with venv():
sudo('python manage.py collectstatic --clear --noinput')
def setup():
"""Configure basic tools."""
with cd(env.root):
run('git clone git://github.com/pyistanbul/website.git ' + env.project_name)
with cd('%(root)s%(project_name)s' % env):
run('virtualenv venv')
with venv():
run('pip install -r conf/requirements.txt')
update_nginx_conf()
update_static()
start()
def setup_vm():
"""Setup the VM."""
sudo('apt-get update && apt-get upgrade && apt-get install git-core '
'python-setuptools python-pip python-dev build-essential '
'nginx curl libcurl3')
sudo('pip install virtualenv')
def clean():
"""Clean the current setup."""
with cd(env.root):
sudo('rm -r %s/' % env.project_name)
sudo('rm /etc/nginx/sites-enabled/' + env.domain)
def clean_pyc():
"""Remove all .pyc files."""
local('find . -name "*.pyc" -exec rm {} \;')