forked from bcambel/pythonhackers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
130 lines (91 loc) · 2.47 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from fabric.api import run, sudo, env, task
from fabric.context_managers import cd
import logging
from fabtools import require
# env.hosts = []
setup = {
'stg': {'dir': '/var/www/stg.pythonhackers.com', 'supervisor': 'staging_pythonhackers'},
'prd': {'dir': '/var/www/beta.pythonhackers.com', 'supervisor': 'prod_pythonhackers'},
}
env.user = 'root'
PACKAGES = [
'supervisor', 'vim', 'htop', 'build-essential',
'postgresql-9.1', 'memcached', 'libpq-dev',
'git-core', 'tig', 'redis-server',
'postgresql-contrib-9.1', 'postgresql-client-9.1',
'python-pip',
]
# 'newrelic-sysmond'
@task
def install_packages():
require.deb.package(PACKAGES)
@task
def venv():
run("pip install virtualenv")
@task
def restart_nginx():
run("service nginx restart")
#"moreutils"
@task
def install_java():
require.deb.packages(["openjdk-7-jdk", "openjdk-7-jre"], update=True)
@task
def restart_process(setup):
project = setup['supervisor']
sudo("supervisorctl restart {}".format(project))
@task
def glog():
with cd(env.root):
run("git log -2")
@task
def update_code(settings):
with cd(settings['dir']):
run("git pull")
# @task
# def install(*packages):
# assert packages is not None
# sudo("apt-get -y install %s" % packages)
@task
def ntp():
require.deb.packages(["ntp"], update=True)
sudo("service ntp restart")
@task
def deploy(settings='stg', restart=False):
setting = setup[settings]
update_code(setting)
logging.warn("Should restart? %s %s" % (restart, bool(restart)))
if bool(restart):
restart_process(setting)
log()
@task
def super(mode=""):
sudo("supervisorctl %s" % mode)
@task
def hostname_check():
run("hostname")
@task
def disc_status():
run("df -h")
@task
def log(directory='/var/log/python/stg.pythonhackers/', tail_file='app.log'):
with cd(directory):
run("tail -f {}".format(tail_file))
@task
def nlog():
with cd("/var/log/nginx/stg.pythonhackers.com"):
run("tail -f access.log")
@task
def rabbitmq():
require.deb.packages(["rabbitmq-server"], update=True)
sudo("service rabbitmq-server restart")
@task
def redis():
require.deb.packages(["redis-server"], update=True)
sudo("service redis-server restart")
@task
def adduser(username, password, pubkey):
require.user(username,
password=password,
ssh_public_keys=pubkey,
shell="/bin/bash")
require.sudoer(username)