-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabfile.py
130 lines (92 loc) · 4.14 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
#!/bin/bash
import os
from boto3.session import Session
from ConfigParser import ConfigParser
from fabric.api import *
ROOT_DIR = os.path.dirname(__file__)
# Get sensitive configuration
config = ConfigParser()
config.read(ROOT_DIR + '/conf/sensitive/configuration.ini')
PROJECT_NAME = config.get('django', 'project_name')
# Deploy server information
if int(config.get('django', 'development_mode')) == 1:
AWS_ACCESS_KEY_ID = config.get('aws', 'access_key_id')
AWS_SECRET_ACCESS_KEY = config.get('aws', 'secret_access_key')
env.hosts = []
env.user = 'ubuntu'
env.key_filename = ROOT_DIR + "/conf/sensitive/remote_server.pem"
env.port = 22
session = Session(aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
region_name='ap-northeast-2') # SEOUL REGION
ec2 = session.resource('ec2')
for instance in ec2.instances.all():
if instance.key_name == 'ping-korea':
env.hosts.append(instance.public_dns_name)
def docker_onboot():
local("sudo service nginx start")
local("sudo service mysql start")
local("sudo service redis-server start")
local("sudo service rabbitmq-server start")
def run_uwsgi():
local("sudo uwsgi --uid www-data --gid www-data --emperor /etc/uwsgi/vassals --master --die-on-term --daemonize=" + ROOT_DIR + "/logs/uwsgi.log --disable-logging")
def stop_uwsgi():
with settings(warn_only=True):
local("ps -ef | grep uwsgi | grep -v grep | awk '{print $2}' | xargs kill -15")
def run_shell():
with lcd(ROOT_DIR):
try:
local("./manage.py shell_plus")
except:
local("./manage.py shell")
def run_dbshell():
with lcd(ROOT_DIR):
local("./manage.py dbshell")
def run_server():
with lcd(ROOT_DIR):
local("./manage.py runserver 0.0.0.0:8000")
def stop_server():
local("sudo fuser -k 8000/tcp")
def run_celery():
with lcd(ROOT_DIR):
local("./manage.py celeryd_detach --logfile=logs/celery_daemon.log --pidfile=logs/celery_daemon.pid")
local("./manage.py celery beat --logfile=logs/celery_beat.log --pidfile=logs/celery_beat.pid --detach")
def stop_celery():
with settings(warn_only=True):
local("ps auxww | grep 'celery worker' | grep -v grep | awk '{print $2}' | xargs kill -15")
with settings(warn_only=True):
local("ps auxww | grep 'celery beat' | grep -v grep | awk '{print $2}' | xargs kill -15")
def clear_celery_tasks():
with lcd(ROOT_DIR):
local("./manage.py celery purge")
def clear_silk_logs():
with lcd(ROOT_DIR):
local("./manage.py silk_clear_request_log")
def update_staticfiles():
with lcd(ROOT_DIR + "/" + PROJECT_NAME + "/static/"):
local("webpack")
with lcd(ROOT_DIR):
local("./manage.py collectstatic --noinput")
local("./manage.py compress --force")
def deploy(*command):
with cd(ROOT_DIR):
sudo("git pull origin master")
if 'SERVER_CODE_UPDATED' in command:
with cd(ROOT_DIR):
sudo("ps -ef | grep uwsgi | grep -v grep | awk '{print $2}' | xargs kill -15")
sudo("uwsgi --uid www-data --gid www-data --emperor /etc/uwsgi/vassals --master --die-on-term --daemonize=" + ROOT_DIR + "/logs/uwsgi.log --disable-logging")
if 'STATIC_FILES_UPDATED' in command:
with cd(ROOT_DIR + "/" + PROJECT_NAME + "/static/"):
sudo("webpack")
with cd(ROOT_DIR):
sudo("./manage.py collectstatic --noinput")
sudo("./manage.py compress --force")
if 'CELERY_RELATED_CODE_UPDATED' in command:
with settings(warn_only=True):
sudo("ps auxww | grep 'celery worker' | grep -v grep | awk '{print $2}' | xargs kill -15")
sudo("ps auxww | grep 'celery beat' | grep -v grep | awk '{print $2}' | xargs kill -15")
with cd(ROOT_DIR):
sudo("./manage.py celeryd_detach --logfile=logs/celery_daemon.log --pidfile=logs/celery_daemon.pid")
sudo("./manage.py celery beat --logfile=logs/celery_beat.log --pidfile=logs/celery_beat.pid --detach")
if 'NGINX_CONFIGURATION_UPDATED' in command:
sudo("service nginx restart")