-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
125 lines (85 loc) · 3.27 KB
/
main.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
from Src.Core import OutputCustomer,Reader,Base
from multiprocessing import Process
from threading import Thread
from webServer.start import start_web
import multiprocessing,os,click
def runReader(log_files_conf,config_name):
r = Reader(log_file_conf=log_files_conf ,config_name=config_name)
pushQueue = ['pushDataToQueue'] * multiprocessing.cpu_count()
jobs = ['readLog','cutFile'] + pushQueue
t = []
for i in jobs:
th = Thread(target=r.runMethod, args=(i, ))
t.append(th)
for i in t:
i.start()
for i in t:
i.join()
def customer( config_name ):
OutputCustomer(config_name).saveToStorage()
def getLogFilsDict(base):
logFiles = []
for i in list(base.conf):
if 'inputer.log_file' in i:
item = dict(base.conf[i])
item['app_name'] = i.split('.')[-1]
logFiles.append(item)
return logFiles
@click.command()
@click.option('-r', '--run', help="run type" ,type=click.Choice(['inputer', 'outputer','web']))
@click.option('-s', '--stop', help="stop the proccess" ,type=click.Choice(['inputer', 'outputer']))
@click.option('-c', '--config', help="config file name" )
def enter(run,stop,config):
if (config == None):
print('please use "-c" to bind config.ini file')
exit()
base = Base(config_name=config)
if (run == 'inputer'):
logFiles = getLogFilsDict(base)
plist = []
for i in logFiles:
p = Process(target=runReader, args=( i, config ,))
plist.append(p)
for i in plist:
i.start()
for i in plist:
i.join()
if (run == 'outputer'):
p_list = []
for start_webi in range(int(base.conf['outputer']['worker_process_num'])):
p = Process(target=customer , args=(config ,) )
p_list.append(p)
for i in p_list:
i.start()
for i in p_list:
i.join()
if (run == 'web'):
web_conf = dict(base.conf['web'])
web_conf[ web_conf['data_engine'] ] = dict(base.conf[ web_conf['data_engine'] ])
start_web(web_conf)
if (stop ):
if isinstance(config,str) and len(config) :
cmd = 'ps -ax | grep "main.py -r %s -c %s"' % (stop, config)
else:
cmd = 'ps -ax | grep "main.py -r %s"' % stop
res = os.popen(cmd)
pids = []
print('|============================================================')
for i in res.readlines():
if i.find('grep') != -1:
continue
print('| %s ' % i.strip())
pids.append(i.strip().split(' ')[0])
if len(pids) == 0:
print('| %s is not running ' % stop)
print('|============================================================')
exit('nothing happened . bye bye !')
print('|============================================================')
confirm = input('confirm: please enter [ yes | y ] or [ no | n ] : ')
if confirm in ['yes','y'] and len(pids) > 0:
os.popen('kill %s' % ' '.join(pids))
exit('pid: %s was killed and %s is stoped. bye bye !' % (' '.join(pids) ,stop) )
else:
exit('nothing happened . bye bye !')
if __name__ == "__main__":
enter()