15 def get_configpath(conffile):
16 confdir = str(os.environ.get(
'ERECO_CONFDIR'))
18 print 'ERECO_CONFDIR is not defined. Exit.'
20 cmd = confdir +
'/' + conffile +
'.conf'
25 def get_ergetconf(conffile, item1, item2='NULL', item3='NULL'):
27 confdir = str(os.environ.get(
'ERECO_CONFDIR'))
29 print 'ERECO_CONFDIR is not defined. Exit.'
31 cmd =
'rfgetconf ' + get_configpath(conffile) +
' ' + item1 +
' ' + item2 \
33 p = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE,
34 stderr=subprocess.PIPE)
36 output = p.stdout.read()
47 def run_nsmd(nsmdir, port, nsmhost):
49 if not os.path.exists(nsmdir +
'/' + nsmhost):
50 os.mkdir(nsmdir +
'/' + nsmhost)
52 nsmd =
"nsmd2 -f -p " \
53 + port +
' -s ' + port +
' -h '
54 cmd =
'ssh ' + nsmhost +
' "cd ' + nsmdir +
'/' + nsmhost \
55 +
'; setenv NSMLOGDIR ' + nsmdir +
'/' + nsmhost +
';' + nsmd \
58 p = subprocess.Popen(cmd, shell=
True)
66 def kill_nsmd(port, nsmhost):
67 cmd =
'ssh ' + nsmhost +
' "ps -fC nsmd2 | grep ' + port \
68 +
"| awk '{print \$2}' \" > temp.pid"
71 p = subprocess.Popen(cmd, shell=
True)
73 for line
in open(
'temp.pid',
'r'):
76 cmd =
'ssh ' + nsmhost +
' "kill ' + str(pid) +
'"'
78 p = subprocess.Popen(cmd, shell=
True)
84 def start_nsmd(conffile):
86 nsmdir = get_ergetconf(conffile,
'system',
'nsmdir_base')
87 port = get_ergetconf(conffile,
'system',
'nsmport')
90 ctlhost = get_ergetconf(conffile,
'master',
'ctlhost')
91 run_nsmd(nsmdir, port, ctlhost)
92 print 'nsmd on %s started' % ctlhost
95 evshost = get_ergetconf(conffile,
'distributor',
'ctlhost')
96 if ctlhost.find(evshost) == -1:
97 run_nsmd(nsmdir, port, evshost)
98 print 'nsmd on %s started' % evshost
101 nnodes = int(get_ergetconf(conffile,
'processor',
'nnodes'))
102 procid = int(get_ergetconf(conffile,
'processor',
'idbase'))
103 badlist = get_ergetconf(conffile,
'processor',
'badlist')
104 evphostbase = get_ergetconf(conffile,
'processor',
'ctlhostbase')
105 for i
in range(procid, procid + nnodes):
107 if badlist.find(nodeid) == -1:
108 evphost = evphostbase + nodeid
109 run_nsmd(nsmdir, port, evphost)
110 print 'nsmd on %s started' % evphost
113 def stop_nsmd(conffile):
114 port = get_ergetconf(conffile,
'system',
'nsmport')
117 ctlhost = get_ergetconf(conffile,
'master',
'ctlhost')
118 kill_nsmd(port, ctlhost)
119 print 'nsmd on %s stopped' % ctlhost
122 evshost = get_ergetconf(conffile,
'distributor',
'ctlhost')
123 if ctlhost.find(evshost) == -1:
124 kill_nsmd(port, evshost)
125 print 'nsmd on %s stopped' % evshost
128 nnodes = int(get_ergetconf(conffile,
'processor',
'nnodes'))
129 procid = int(get_ergetconf(conffile,
'processor',
'idbase'))
130 badlist = get_ergetconf(conffile,
'processor',
'badlist')
131 evphostbase = get_ergetconf(conffile,
'processor',
'ctlhostbase')
132 for i
in range(procid, procid + nnodes):
134 if badlist.find(nodeid) == -1:
135 evphost = evphostbase + nodeid
136 kill_nsmd(port, evphost)
137 print 'nsmd on %s stopped' % evphost
143 def run_distributor(conffile):
144 evshost = get_ergetconf(conffile,
'distributor',
'ctlhost')
145 basedir = get_ergetconf(conffile,
'system',
'execdir_base')
146 port = get_ergetconf(conffile,
'system',
'nsmport')
147 if not os.path.exists(basedir +
'/distributor'):
148 os.mkdir(basedir +
'/distributor')
149 cmd =
'ssh ' + evshost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' + port \
150 +
'; ereco_distributor ' + get_configpath(conffile) \
151 +
' > & distributor/nsmlog.log" '
153 p = subprocess.Popen(cmd, shell=
True)
159 def stop_distributor(conffile):
160 evshost = get_ergetconf(conffile,
'distributor',
'ctlhost')
161 basedir = get_ergetconf(conffile,
'system',
'execdir_base')
162 unit = get_ergetconf(conffile,
'system',
'unitname')
163 ringbuf = get_ergetconf(conffile,
'distributor',
'ringbuffer')
164 rbufname = unit +
':' + ringbuf
165 shmname = unit +
':distributor'
166 p = subprocess.Popen(
'rfcommand ' + conffile +
167 ' distributor RC_ABORT', shell=
True)
169 pidfile = basedir +
'/distributor/pid.data'
170 for pid
in open(pidfile,
'r'):
171 cmd =
'ssh ' + evshost +
' "kill ' + pid +
'; removerb ' + rbufname \
172 +
"; removeshm " + shmname +
'"'
174 p = subprocess.Popen(cmd, shell=
True)
180 def run_eventprocessor(conffile):
181 hostbase = get_ergetconf(conffile,
'processor',
'ctlhostbase')
182 nodebase = get_ergetconf(conffile,
'processor',
'nodebase')
183 basedir = get_ergetconf(conffile,
'system',
'execdir_base')
184 port = get_ergetconf(conffile,
'system',
'nsmport')
185 nnodes = int(get_ergetconf(conffile,
'processor',
'nnodes'))
186 procid = int(get_ergetconf(conffile,
'processor',
'idbase'))
187 badlist = get_ergetconf(conffile,
'processor',
'badlist')
188 id = int(get_ergetconf(conffile,
'processor',
'idbase'))
190 for i
in range(procid, procid + nnodes):
192 if badlist.find(nodeid) == -1:
193 evphost = hostbase + nodeid
194 nodename = nodebase + nodeid
195 if not os.path.exists(basedir +
'/evp_' + nodename):
196 os.mkdir(basedir +
'/evp_' + nodename)
197 cmd =
'ssh ' + evphost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' \
198 + port +
'; ereco_eventprocessor ' + get_configpath(conffile) \
199 +
' > & evp_' + nodename +
'/nsmlog.log" '
201 p = subprocess.Popen(cmd, shell=
True)
207 def stop_eventprocessor(conffile):
208 hostbase = get_ergetconf(conffile,
'processor',
'ctlhostbase')
209 nodebase = get_ergetconf(conffile,
'processor',
'nodebase')
210 basedir = get_ergetconf(conffile,
'system',
'execdir_base')
211 port = get_ergetconf(conffile,
'system',
'nsmport')
212 nnodes = int(get_ergetconf(conffile,
'processor',
'nnodes'))
213 procid = int(get_ergetconf(conffile,
'processor',
'idbase'))
214 badlist = get_ergetconf(conffile,
'processor',
'badlist')
215 id = int(get_ergetconf(conffile,
'processor',
'idbase'))
217 unit = get_ergetconf(conffile,
'system',
'unitname')
218 rbufin = get_ergetconf(conffile,
'collector',
'ringbufin')
219 rbufout = get_ergetconf(conffile,
'collector',
'ringbufout')
220 rbufinname = unit +
':' + rbufin
221 rbufoutname = unit +
':' + rbufout
223 for i
in range(procid, procid + nnodes):
225 if badlist.find(nodeid) == -1:
226 evphost = hostbase + nodeid
227 nodename =
'evp_' + nodebase + nodeid
228 shmname = unit +
':' + nodename
230 p = subprocess.Popen(
'rfcommand ' + conffile +
' ' + nodename +
231 ' RC_ABORT', shell=
True)
233 pidfile = basedir +
'/' + nodename +
'/pid.data'
234 for pid
in open(pidfile,
'r'):
235 cmd =
'ssh ' + evphost +
' "kill ' + pid +
'; removerb ' \
236 + rbufinname +
'; removerb ' + rbufoutname \
237 +
'; removeshm ' + shmname +
'; clear_basf2_ipc"'
241 p = subprocess.Popen(cmd, shell=
True)
247 def run_dqmserver(conffile):
248 dqmhost = get_ergetconf(conffile,
'dqmserver',
'ctlhost')
249 basedir = get_ergetconf(conffile,
'system',
'execdir_base')
250 port = get_ergetconf(conffile,
'system',
'nsmport')
251 if not os.path.exists(basedir +
'/dqmserver'):
252 os.mkdir(basedir +
'/dqmserver')
253 cmd =
'ssh ' + dqmhost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' + port \
254 +
'; rf_dqmserver ' + get_configpath(conffile) \
255 +
' > & dqmserver/nsmlog.log" '
257 p = subprocess.Popen(cmd, shell=
True)
263 def stop_dqmserver(conffile):
264 dqmhost = get_ergetconf(conffile,
'dqmserver',
'ctlhost')
265 basedir = get_ergetconf(conffile,
'system',
'execdir_base')
266 p = subprocess.Popen(
'rfcommand ' + conffile +
' dqmserver RC_ABORT', shell=
True)
268 pidfile = basedir +
'/dqmserver/pid.data'
269 for pid
in open(pidfile,
'r'):
270 cmd =
'ssh ' + dqmhost +
' "kill ' + pid +
'"'
272 p = subprocess.Popen(cmd, shell=
True)
278 def run_eventsampler(conffile):
279 samplerhost = get_ergetconf(conffile,
'eventsampler',
'ctlhost')
280 basedir = get_ergetconf(conffile,
'system',
'execdir_base')
281 port = get_ergetconf(conffile,
'system',
'nsmport')
282 if not os.path.exists(basedir +
'/sampler'):
283 os.mkdir(basedir +
'/sampler')
284 cmd =
'ssh ' + samplerhost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' + port \
285 +
'; ereco_eventsampler ' + get_configpath(conffile) \
286 +
' > & sampler/nsmlog.log" '
288 p = subprocess.Popen(cmd, shell=
True)
294 def stop_eventsampler(conffile):
295 samplerhost = get_ergetconf(conffile,
'eventsampler',
'ctlhost')
296 basedir = get_ergetconf(conffile,
'system',
'execdir_base')
297 p = subprocess.Popen(
'rfcommand ' + conffile +
' sampler RC_ABORT', shell=
True)
299 pidfile = basedir +
'/sampler/pid.data'
300 for pid
in open(pidfile,
'r'):
301 cmd =
'ssh ' + samplerhost +
' "kill ' + pid +
'"'
303 p = subprocess.Popen(cmd, shell=
True)
309 def run_master(conffile):
310 masterhost = get_ergetconf(conffile,
'master',
'ctlhost')
311 basedir = get_ergetconf(conffile,
'system',
'execdir_base')
312 port = get_ergetconf(conffile,
'system',
'nsmport')
313 if not os.path.exists(basedir +
'/master'):
314 os.mkdir(basedir +
'/master')
315 cmd =
'ssh ' + masterhost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' \
316 + port +
'; ereco_master_local ' + get_configpath(conffile) \
317 +
' > & master/nsmlog.log" '
319 p = subprocess.Popen(cmd, shell=
True)
325 def stop_master(conffile):
326 masterhost = get_ergetconf(conffile,
'master',
'ctlhost')
327 basedir = get_ergetconf(conffile,
'system',
'execdir_base')
330 pidfile = basedir +
'/master/pid.data'
331 for pid
in open(pidfile,
'r'):
332 cmd =
'ssh ' + masterhost +
' "kill ' + pid +
'"'
334 p = subprocess.Popen(cmd, shell=
True)
338 def start_ereco_components(conffile):
339 run_eventprocessor(conffile)
340 run_distributor(conffile)
341 run_dqmserver(conffile)
342 run_eventsampler(conffile)
347 def stop_ereco_components(conffile):
348 stop_eventsampler(conffile)
349 stop_dqmserver(conffile)
350 stop_distributor(conffile)
351 stop_eventprocessor(conffile)
356 def start_ereco_local(conffile):
357 start_ereco_components(conffile)
363 def stop_ereco_local(conffile):
365 stop_ereco_components(conffile)
366 stop_master(conffile)