-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
84 lines (67 loc) · 2.32 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from fabric.api import env, get, local, put, run
import os
from time import sleep
from datetime import datetime
from tempfile import mkdtemp
FILES = []
EXT = ('py', 'json')
NO_UPLOAD = ('fabfile.py')
PRESERVE_FILES = (
'conf/collector.json',
)
APP_NAME = 'snoopy_oo'
APP_PACKAGE = '%s-%s.tbz2' % (APP_NAME,
datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S'))
APP_PATH = '/opt/cyclelogic/%s' % (APP_NAME)
all_files = os.walk('./')
for path, dirnames, filenames in all_files:
for filename in filenames:
if filename in NO_UPLOAD:
continue
else:
file_extension = filename.split('.')[-1]
if file_extension in EXT:
if path[2:]:
FILES.append('%s/%s' % (path[2:], filename))
else:
FILES.append('%s' % (filename))
def staging():
env.hosts = ['192.168.23.240']
env.user = 'deployer'
env.password = 'deployer'
def production():
env.hosts = ['192.168.149.39', '192.168.149.18']
env.user = 'root'
env.password = 'Password1'
def restart():
run('sudo /etc/init.d/snoopy-collector restart')
def update(is_install=False):
'Install the application (?)'
# Copio el proyecto a una carpeta temporal
tmp_dir = mkdtemp(prefix='%s_' % (APP_NAME))
local('tar c %s | tar xC %s' % (' '.join(FILES), tmp_dir))
# Copio desde produccion archivos importantes
if is_install == False:
for element in PRESERVE_FILES:
destination = element.replace(element.split('/')[-1], '')
destination = '%s/%s' % (tmp_dir, destination)
if not os.path.exists(destination):
local('mkdir -p %s' % (destination))
get('%s/%s' % (APP_PATH, element), destination)
try:
local('mv %s/%s.%s %s/%s' % (tmp_dir, element, env.host,
tmp_dir, element))
except:
pass
# Creo paquete del proyecto temporal y subo
local('cd %s && tar cjf %s *' % (tmp_dir, APP_PACKAGE))
put('%s/%s' % (tmp_dir, APP_PACKAGE), APP_PACKAGE)
run('rm -rf %s/*' % (APP_PATH))
run('tar xjf %s -C %s' % (APP_PACKAGE, APP_PATH))
run('rm %s' % (APP_PACKAGE))
restart()
def install():
run('mkdir -p %s' % (APP_PATH))
update(is_install=True)