16 def get_configpath(conffile):
17 confdir = str(os.environ.get(
'RFARM_CONFDIR'))
19 print 'RFARM_CONFDIR is not defined. Exit.'
21 cmd = confdir +
'/' + conffile +
'.conf'
26 def get_rfgetconf(conffile, item1, item2='NULL', item3='NULL'):
28 confdir = str(os.environ.get(
'RFARM_CONFDIR'))
30 print 'RFARM_CONFDIR is not defined. Exit.'
32 cmd =
'rfgetconf ' + get_configpath(conffile) +
' ' + item1 +
' ' + item2 \
34 p = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE,
35 stderr=subprocess.PIPE)
37 output = p.stdout.read()
48 def run_nsmd(nsmdir, port, nsmhost):
50 if not os.path.exists(nsmdir +
'/' + nsmhost):
51 os.mkdir(nsmdir +
'/' + nsmhost)
52 nsmd = str(os.environ.get(
'BELLE2_EXTERNALS_BIN')) +
'/nsmd2 -f -p ' \
53 + port +
' -s ' + port +
' -h '
54 cmd =
'ssh ' + nsmhost +
' "cd ' + nsmdir +
'/' + nsmhost \
55 +
'; export 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_rfgetconf(conffile,
'system',
'nsmdir_base')
87 port = get_rfgetconf(conffile,
'system',
'nsmport')
90 ctlhost = get_rfgetconf(conffile,
'master',
'ctlhost')
91 run_nsmd(nsmdir, port, ctlhost)
92 print 'nsmd on %s started' % ctlhost
95 evshost = get_rfgetconf(conffile,
'distributor',
'ctlhost')
96 if ctlhost.find(evshost) == -1:
97 run_nsmd(nsmdir, port, evshost)
98 print 'nsmd on %s started' % evshost
101 opshost = get_rfgetconf(conffile,
'collector',
'ctlhost')
102 run_nsmd(nsmdir, port, opshost)
103 print 'nsmd on %s started' % opshost
106 nnodes = int(get_rfgetconf(conffile,
'processor',
'nnodes'))
107 procid = int(get_rfgetconf(conffile,
'processor',
'idbase'))
108 badlist = get_rfgetconf(conffile,
'processor',
'badlist')
109 evphostbase = get_rfgetconf(conffile,
'processor',
'ctlhostbase')
110 for i
in range(procid, procid + nnodes):
113 if badlist.find(nodeid) == -1:
114 evphost = evphostbase + nodeid
115 run_nsmd(nsmdir, port, evphost)
116 print 'nsmd on %s started' % evphost
119 def stop_nsmd(conffile):
120 port = get_rfgetconf(conffile,
'system',
'nsmport')
123 ctlhost = get_rfgetconf(conffile,
'master',
'ctlhost')
124 kill_nsmd(port, ctlhost)
125 print 'nsmd on %s stopped' % ctlhost
128 evshost = get_rfgetconf(conffile,
'distributor',
'ctlhost')
129 if ctlhost.find(evshost) == -1:
130 kill_nsmd(port, evshost)
131 print 'nsmd on %s stopped' % evshost
134 opshost = get_rfgetconf(conffile,
'collector',
'ctlhost')
135 kill_nsmd(port, opshost)
136 print 'nsmd on %s stopped' % opshost
139 nnodes = int(get_rfgetconf(conffile,
'processor',
'nnodes'))
140 procid = int(get_rfgetconf(conffile,
'processor',
'idbase'))
141 badlist = get_rfgetconf(conffile,
'processor',
'badlist')
142 evphostbase = get_rfgetconf(conffile,
'processor',
'ctlhostbase')
143 for i
in range(procid, procid + nnodes):
146 if badlist.find(nodeid) == -1:
147 evphost = evphostbase + nodeid
148 kill_nsmd(port, evphost)
149 print 'nsmd on %s stopped' % evphost
155 def run_eventserver(conffile):
156 evshost = get_rfgetconf(conffile,
'distributor',
'ctlhost')
157 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
158 port = get_rfgetconf(conffile,
'system',
'nsmport')
159 if not os.path.exists(basedir +
'/distributor'):
160 os.mkdir(basedir +
'/distributor')
161 cmd =
'ssh ' + evshost +
' "cd ' + basedir +
'; export NSM2_PORT=' + port \
162 +
'; rf_eventserver ' + get_configpath(conffile) \
163 +
' &> distributor/nsmlog.log" '
165 p = subprocess.Popen(cmd, shell=
True)
171 def stop_eventserver(conffile):
172 evshost = get_rfgetconf(conffile,
'distributor',
'ctlhost')
173 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
174 unit = get_rfgetconf(conffile,
'system',
'unitname')
175 ringbuf = get_rfgetconf(conffile,
'distributor',
'ringbuffer')
176 rbufname = unit +
':' + ringbuf
177 shmname = unit +
':distributor'
178 p = subprocess.Popen(
'rfcommand ' + conffile +
179 ' distributor RF_UNCONFIGURE', shell=
True)
181 pidfile = basedir +
'/distributor/pid.data'
182 for pid
in open(pidfile,
'r'):
183 cmd =
'ssh ' + evshost +
' "kill ' + pid +
'; removerb ' + rbufname \
184 +
"; removeshm " + shmname +
'"'
186 p = subprocess.Popen(cmd, shell=
True)
192 def run_outputserver(conffile):
193 opshost = get_rfgetconf(conffile,
'collector',
'ctlhost')
194 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
195 port = get_rfgetconf(conffile,
'system',
'nsmport')
196 if not os.path.exists(basedir +
'/collector'):
197 os.mkdir(basedir +
'/collector')
198 cmd =
'ssh ' + opshost +
' "cd ' + basedir +
'; export NSM2_PORT=' + port \
199 +
'; rf_outputserver ' + get_configpath(conffile) \
200 +
' &> collector/nsmlog.log" '
202 p = subprocess.Popen(cmd, shell=
True)
208 def stop_outputserver(conffile):
209 opshost = get_rfgetconf(conffile,
'collector',
'ctlhost')
210 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
211 unit = get_rfgetconf(conffile,
'system',
'unitname')
212 rbufin = get_rfgetconf(conffile,
'collector',
'ringbufin')
213 rbufout = get_rfgetconf(conffile,
'collector',
'ringbufout')
214 rbufinname = unit +
':' + rbufin
215 rbufoutname = unit +
':' + rbufout
216 shmname = unit +
':collector'
217 p = subprocess.Popen(
'rfcommand ' + conffile +
' collector RF_UNCONFIGURE', shell=
True)
219 pidfile = basedir +
'/collector/pid.data'
220 for pid
in open(pidfile,
'r'):
221 cmd =
'ssh ' + opshost +
' "kill ' + pid +
'; removerb ' + rbufinname \
222 +
'; removerb ' + rbufoutname +
'; removeshm ' + shmname \
223 +
'; clear_basf2_ipc"'
225 p = subprocess.Popen(cmd, shell=
True)
231 def run_eventprocessor(conffile):
232 hostbase = get_rfgetconf(conffile,
'processor',
'ctlhostbase')
233 nodebase = get_rfgetconf(conffile,
'processor',
'nodebase')
234 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
235 port = get_rfgetconf(conffile,
'system',
'nsmport')
236 nnodes = int(get_rfgetconf(conffile,
'processor',
'nnodes'))
237 procid = int(get_rfgetconf(conffile,
'processor',
'idbase'))
238 badlist = get_rfgetconf(conffile,
'processor',
'badlist')
239 id = int(get_rfgetconf(conffile,
'processor',
'idbase'))
241 for i
in range(procid, procid + nnodes):
242 nodenum =
'%2.2d' % i
244 if badlist.find(nodeid) == -1:
245 evphost = hostbase + nodeid
246 nodename = nodebase + nodenum
247 if not os.path.exists(basedir +
'/evp_' + nodename):
248 os.mkdir(basedir +
'/evp_' + nodename)
249 cmd =
'ssh ' + evphost +
' "cd ' + basedir +
'; export NSM2_PORT=' \
250 + port +
'; rf_eventprocessor ' + get_configpath(conffile) \
251 +
' &> evp_' + nodename +
'/nsmlog.log" '
253 p = subprocess.Popen(cmd, shell=
True)
259 def stop_eventprocessor(conffile):
260 hostbase = get_rfgetconf(conffile,
'processor',
'ctlhostbase')
261 nodebase = get_rfgetconf(conffile,
'processor',
'nodebase')
262 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
263 port = get_rfgetconf(conffile,
'system',
'nsmport')
264 nnodes = int(get_rfgetconf(conffile,
'processor',
'nnodes'))
265 procid = int(get_rfgetconf(conffile,
'processor',
'idbase'))
266 badlist = get_rfgetconf(conffile,
'processor',
'badlist')
267 id = int(get_rfgetconf(conffile,
'processor',
'idbase'))
269 unit = get_rfgetconf(conffile,
'system',
'unitname')
270 rbufin = get_rfgetconf(conffile,
'collector',
'ringbufin')
271 rbufout = get_rfgetconf(conffile,
'collector',
'ringbufout')
272 rbufinname = unit +
':' + rbufin
273 rbufoutname = unit +
':' + rbufout
275 for i
in range(procid, procid + nnodes):
278 if badlist.find(nodeid) == -1:
279 evphost = hostbase + nodeid
280 nodename =
'evp_' + nodebase + nodeid
281 shmname = unit +
':' + nodename
283 p = subprocess.Popen(
'rfcommand ' + conffile +
' ' + nodename +
284 ' RF_UNCONFIGURE', shell=
True)
286 pidfile = basedir +
'/' + nodename +
'/pid.data'
287 for pid
in open(pidfile,
'r'):
288 cmd =
'ssh ' + evphost +
' "kill ' + pid +
'; removerb ' \
289 + rbufinname +
'; removerb ' + rbufoutname \
290 +
'; removeshm ' + shmname +
'; clear_basf2_ipc"'
294 p = subprocess.Popen(cmd, shell=
True)
300 def run_dqmserver(conffile):
301 dqmhost = get_rfgetconf(conffile,
'dqmserver',
'ctlhost')
302 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
303 port = get_rfgetconf(conffile,
'system',
'nsmport')
304 if not os.path.exists(basedir +
'/dqmserver'):
305 os.mkdir(basedir +
'/dqmserver')
306 cmd =
'ssh ' + dqmhost +
' "cd ' + basedir +
'; export NSM2_PORT=' + port \
307 +
'; rf_dqmserver ' + get_configpath(conffile) \
308 +
' &> dqmserver/nsmlog.log" '
310 p = subprocess.Popen(cmd, shell=
True)
316 def stop_dqmserver(conffile):
317 dqmhost = get_rfgetconf(conffile,
'dqmserver',
'ctlhost')
318 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
319 p = subprocess.Popen(
'rfcommand ' + conffile +
' dqmserver RF_UNCONFIGURE', shell=
True)
321 pidfile = basedir +
'/dqmserver/pid.data'
322 for pid
in open(pidfile,
'r'):
323 cmd =
'ssh ' + dqmhost +
' "kill ' + pid +
'"'
325 p = subprocess.Popen(cmd, shell=
True)
331 def run_roisender(conffile):
332 roihost = get_rfgetconf(conffile,
'roisender',
'ctlhost')
333 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
334 port = get_rfgetconf(conffile,
'system',
'nsmport')
335 if not os.path.exists(basedir +
'/roisender'):
336 os.mkdir(basedir +
'/roisender')
337 cmd =
'ssh ' + roihost +
' "cd ' + basedir +
'; export NSM2_PORT=' + port \
338 +
'; rf_roisender ' + get_configpath(conffile) \
339 +
' &> roisender/nsmlog.log" '
341 p = subprocess.Popen(cmd, shell=
True)
347 def stop_roisender(conffile):
348 roihost = get_rfgetconf(conffile,
'roisender',
'ctlhost')
349 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
350 unit = get_rfgetconf(conffile,
'system',
'unitname')
351 shmname = unit +
':roisender'
352 p = subprocess.Popen(
'rfcommand ' + conffile +
' roisender RF_UNCONFIGURE', shell=
True)
354 pidfile = basedir +
'/roisender/pid.data'
355 for pid
in open(pidfile,
'r'):
356 cmd =
'ssh ' + roihost +
' "kill ' + pid +
'; removeshm ' + shmname +
'"'
358 p = subprocess.Popen(cmd, shell=
True)
364 def run_master(conffile):
365 masterhost = get_rfgetconf(conffile,
'master',
'ctlhost')
366 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
367 port = get_rfgetconf(conffile,
'system',
'nsmport')
368 if not os.path.exists(basedir +
'/master'):
369 os.mkdir(basedir +
'/master')
370 cmd =
'ssh ' + masterhost +
' "cd ' + basedir +
'; export NSM2_PORT=' \
371 + port +
'; rf_master_local ' + get_configpath(conffile) \
372 +
' &> master/nsmlog.log" '
374 p = subprocess.Popen(cmd, shell=
True)
380 def stop_master(conffile):
381 masterhost = get_rfgetconf(conffile,
'master',
'ctlhost')
382 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
385 pidfile = basedir +
'/master/pid.data'
386 for pid
in open(pidfile,
'r'):
387 cmd =
'ssh ' + masterhost +
' "kill ' + pid +
'"'
389 p = subprocess.Popen(cmd, shell=
True)
393 def start_rfarm_components(conffile):
394 run_eventprocessor(conffile)
395 run_outputserver(conffile)
396 run_eventserver(conffile)
397 run_dqmserver(conffile)
398 run_roisender(conffile)
403 def stop_rfarm_components(conffile):
404 stop_roisender(conffile)
405 stop_dqmserver(conffile)
406 stop_eventserver(conffile)
407 stop_outputserver(conffile)
408 stop_eventprocessor(conffile)
413 def start_rfarm_local(conffile):
414 start_rfarm_components(conffile)
420 def stop_rfarm_local(conffile):
422 stop_rfarm_components(conffile)
423 stop_master(conffile)