21def get_configpath(conffile):
22 confdir = str(os.environ.get(
'RFARM_CONFDIR'))
24 print(
'RFARM_CONFDIR is not defined. Exit.')
26 cmd = confdir +
'/' + conffile +
'.conf'
31def get_rfgetconf(conffile, item1, item2='NULL', item3='NULL'):
33 confdir = str(os.environ.get(
'RFARM_CONFDIR'))
35 print(
'RFARM_CONFDIR is not defined. Exit.')
37 cmd =
'rfgetconf ' + get_configpath(conffile) +
' ' + item1 +
' ' + item2 \
39 p = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE,
40 stderr=subprocess.PIPE)
42 output = p.stdout.read()
53def run_nsmd(nsmdir, port, nsmhost):
55 if not os.path.exists(nsmdir +
'/' + nsmhost):
56 os.mkdir(nsmdir +
'/' + nsmhost)
58 nsmd =
'nsmd2 -f -p ' \
59 + port +
' -s ' + port +
' -h '
60 cmd =
'ssh ' + nsmhost +
' "cd ' + nsmdir +
'/' + nsmhost \
61 +
'; setenv NSMLOGDIR ' + nsmdir +
'/' + nsmhost +
';' + nsmd \
64 subprocess.Popen(cmd, shell=
True)
72def kill_nsmd(port, nsmhost):
73 cmd =
'ssh ' + nsmhost +
' "ps -fC nsmd2 | grep ' + port \
74 +
"| awk '{print \\$2}' \" > temp.pid"
77 p = subprocess.Popen(cmd, shell=
True)
79 for line
in open(
'temp.pid',
'r'):
82 cmd =
'ssh ' + nsmhost +
' "kill ' + str(pid) +
'"'
84 p = subprocess.Popen(cmd, shell=
True)
90def start_nsmd(conffile):
92 nsmdir = get_rfgetconf(conffile,
'system',
'nsmdir_base')
93 port = get_rfgetconf(conffile,
'system',
'nsmport')
96 ctlhost = get_rfgetconf(conffile,
'master',
'ctlhost')
97 run_nsmd(nsmdir, port, ctlhost)
98 print(
'nsmd on %s started' % ctlhost)
101 evshost = get_rfgetconf(conffile,
'distributor',
'ctlhost')
102 if ctlhost.find(evshost) == -1:
103 run_nsmd(nsmdir, port, evshost)
104 print(
'nsmd on %s started' % evshost)
107 opshost = get_rfgetconf(conffile,
'collector',
'ctlhost')
108 run_nsmd(nsmdir, port, opshost)
109 print(
'nsmd on %s started' % opshost)
112 nnodes = int(get_rfgetconf(conffile,
'processor',
'nnodes'))
113 procid = int(get_rfgetconf(conffile,
'processor',
'idbase'))
114 badlist = get_rfgetconf(conffile,
'processor',
'badlist')
115 evphostbase = get_rfgetconf(conffile,
'processor',
'ctlhostbase')
116 for i
in range(procid, procid + nnodes):
118 if badlist.find(nodeid) == -1:
119 evphost = evphostbase + nodeid
120 run_nsmd(nsmdir, port, evphost)
121 print(
'nsmd on %s started' % evphost)
124def stop_nsmd(conffile):
125 port = get_rfgetconf(conffile,
'system',
'nsmport')
128 ctlhost = get_rfgetconf(conffile,
'master',
'ctlhost')
129 kill_nsmd(port, ctlhost)
130 print(
'nsmd on %s stopped' % ctlhost)
133 evshost = get_rfgetconf(conffile,
'distributor',
'ctlhost')
134 if ctlhost.find(evshost) == -1:
135 kill_nsmd(port, evshost)
136 print(
'nsmd on %s stopped' % evshost)
139 opshost = get_rfgetconf(conffile,
'collector',
'ctlhost')
140 kill_nsmd(port, opshost)
141 print(
'nsmd on %s stopped' % opshost)
144 nnodes = int(get_rfgetconf(conffile,
'processor',
'nnodes'))
145 procid = int(get_rfgetconf(conffile,
'processor',
'idbase'))
146 badlist = get_rfgetconf(conffile,
'processor',
'badlist')
147 evphostbase = get_rfgetconf(conffile,
'processor',
'ctlhostbase')
148 for i
in range(procid, procid + nnodes):
150 if badlist.find(nodeid) == -1:
151 evphost = evphostbase + nodeid
152 kill_nsmd(port, evphost)
153 print(
'nsmd on %s stopped' % evphost)
159def run_eventserver(conffile):
160 evshost = get_rfgetconf(conffile,
'distributor',
'ctlhost')
161 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
162 port = get_rfgetconf(conffile,
'system',
'nsmport')
163 if not os.path.exists(basedir +
'/distributor'):
164 os.mkdir(basedir +
'/distributor')
165 cmd =
'ssh ' + evshost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' + port \
166 +
'; rf_eventserver ' + get_configpath(conffile) \
167 +
' > & distributor/nsmlog.log" '
169 subprocess.Popen(cmd, shell=
True)
175def stop_eventserver(conffile):
176 evshost = get_rfgetconf(conffile,
'distributor',
'ctlhost')
177 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
178 unit = get_rfgetconf(conffile,
'system',
'unitname')
179 ringbuf = get_rfgetconf(conffile,
'distributor',
'ringbuffer')
180 rbufname = unit +
':' + ringbuf
181 shmname = unit +
':distributor'
185 pidfile = basedir +
'/distributor/pid.data'
186 for pid
in open(pidfile,
'r'):
187 cmd =
'ssh ' + evshost +
' "kill ' + pid +
'; removerb ' + rbufname \
188 +
"; removeshm " + shmname +
'"'
190 p = subprocess.Popen(cmd, shell=
True)
196def run_outputserver(conffile):
197 opshost = get_rfgetconf(conffile,
'collector',
'ctlhost')
198 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
199 port = get_rfgetconf(conffile,
'system',
'nsmport')
200 if not os.path.exists(basedir +
'/collector'):
201 os.mkdir(basedir +
'/collector')
202 cmd =
'ssh ' + opshost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' + port \
203 +
'; rf_outputserver ' + get_configpath(conffile) \
204 +
' > & collector/nsmlog.log" '
206 subprocess.Popen(cmd, shell=
True)
212def stop_outputserver(conffile):
213 opshost = get_rfgetconf(conffile,
'collector',
'ctlhost')
214 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
215 unit = get_rfgetconf(conffile,
'system',
'unitname')
216 rbufin = get_rfgetconf(conffile,
'collector',
'ringbufin')
217 rbufout = get_rfgetconf(conffile,
'collector',
'ringbufout')
218 rbufinname = unit +
':' + rbufin
219 rbufoutname = unit +
':' + rbufout
220 shmname = unit +
':collector'
223 pidfile = basedir +
'/collector/pid.data'
224 for pid
in open(pidfile,
'r'):
225 cmd =
'ssh ' + opshost +
' "kill ' + pid +
'; removerb ' + rbufinname \
226 +
'; removerb ' + rbufoutname +
'; removeshm ' + shmname \
227 +
'; clear_basf2_ipc"'
229 p = subprocess.Popen(cmd, shell=
True)
235def run_eventprocessor(conffile):
236 hostbase = get_rfgetconf(conffile,
'processor',
'ctlhostbase')
237 nodebase = get_rfgetconf(conffile,
'processor',
'nodebase')
238 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
239 port = get_rfgetconf(conffile,
'system',
'nsmport')
240 nnodes = int(get_rfgetconf(conffile,
'processor',
'nnodes'))
241 procid = int(get_rfgetconf(conffile,
'processor',
'idbase'))
242 badlist = get_rfgetconf(conffile,
'processor',
'badlist')
243 id = int(get_rfgetconf(conffile,
'processor',
'idbase'))
245 for i
in range(procid, procid + nnodes):
247 if badlist.find(nodeid) == -1:
248 evphost = hostbase + nodeid
249 nodename = nodebase + nodeid
250 if not os.path.exists(basedir +
'/evp_' + nodename):
251 os.mkdir(basedir +
'/evp_' + nodename)
252 cmd =
'ssh ' + evphost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' \
253 + port +
'; rf_eventprocessor ' + get_configpath(conffile) \
254 +
' > & evp_' + nodename +
'/nsmlog.log" '
256 subprocess.Popen(cmd, shell=
True)
262def stop_eventprocessor(conffile):
263 hostbase = get_rfgetconf(conffile,
'processor',
'ctlhostbase')
264 nodebase = get_rfgetconf(conffile,
'processor',
'nodebase')
265 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
266 port = get_rfgetconf(conffile,
'system',
'nsmport')
267 nnodes = int(get_rfgetconf(conffile,
'processor',
'nnodes'))
268 procid = int(get_rfgetconf(conffile,
'processor',
'idbase'))
269 badlist = get_rfgetconf(conffile,
'processor',
'badlist')
270 id = int(get_rfgetconf(conffile,
'processor',
'idbase'))
272 unit = get_rfgetconf(conffile,
'system',
'unitname')
273 rbufin = get_rfgetconf(conffile,
'collector',
'ringbufin')
274 rbufout = get_rfgetconf(conffile,
'collector',
'ringbufout')
275 rbufinname = unit +
':' + rbufin
276 rbufoutname = unit +
':' + rbufout
278 for i
in range(procid, procid + nnodes):
280 if badlist.find(nodeid) == -1:
281 evphost = hostbase + nodeid
282 nodename =
'evp_' + nodebase + nodeid
283 shmname = unit +
':' + nodename
288 pidfile = basedir +
'/' + nodename +
'/pid.data'
289 for pid
in open(pidfile,
'r'):
290 cmd =
'ssh ' + evphost +
' "kill ' + pid +
'; removerb ' \
291 + rbufinname +
'; removerb ' + rbufoutname \
292 +
'; removeshm ' + shmname +
'; clear_basf2_ipc"'
296 p = subprocess.Popen(cmd, shell=
True)
302def run_dqmserver(conffile):
303 dqmhost = get_rfgetconf(conffile,
'dqmserver',
'ctlhost')
304 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
305 port = get_rfgetconf(conffile,
'system',
'nsmport')
306 if not os.path.exists(basedir +
'/dqmserver'):
307 os.mkdir(basedir +
'/dqmserver')
308 cmd =
'ssh ' + dqmhost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' + port \
309 +
'; rf_dqmserver ' + get_configpath(conffile) \
310 +
' > & dqmserver/nsmlog.log" '
312 subprocess.Popen(cmd, shell=
True)
318def stop_dqmserver(conffile):
319 dqmhost = get_rfgetconf(conffile,
'dqmserver',
'ctlhost')
320 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
323 pidfile = basedir +
'/dqmserver/pid.data'
324 for pid
in open(pidfile,
'r'):
325 cmd =
'ssh ' + dqmhost +
' "kill ' + pid +
'"'
327 p = subprocess.Popen(cmd, shell=
True)
333def run_roisender(conffile):
334 roihost = get_rfgetconf(conffile,
'roisender',
'ctlhost')
335 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
336 port = get_rfgetconf(conffile,
'system',
'nsmport')
337 if not os.path.exists(basedir +
'/roisender'):
338 os.mkdir(basedir +
'/roisender')
339 cmd =
'ssh ' + roihost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' + port \
340 +
'; rf_roisender ' + get_configpath(conffile) \
341 +
' > & roisender/nsmlog.log" '
343 subprocess.Popen(cmd, shell=
True)
349def stop_roisender(conffile):
350 roihost = get_rfgetconf(conffile,
'roisender',
'ctlhost')
351 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
352 unit = get_rfgetconf(conffile,
'system',
'unitname')
353 shmname = unit +
':roisender'
356 pidfile = basedir +
'/roisender/pid.data'
357 for pid
in open(pidfile,
'r'):
358 cmd =
'ssh ' + roihost +
' "kill ' + pid +
'; removeshm ' + shmname +
'"'
360 p = subprocess.Popen(cmd, shell=
True)
366def run_master(conffile):
367 masterhost = get_rfgetconf(conffile,
'master',
'ctlhost')
368 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
369 port = get_rfgetconf(conffile,
'system',
'nsmport')
370 if not os.path.exists(basedir +
'/master'):
371 os.mkdir(basedir +
'/master')
372 cmd =
'ssh ' + masterhost +
' "cd ' + basedir +
'; setenv NSM2_PORT ' \
373 + port +
'; rf_master_local ' + get_configpath(conffile) \
374 +
' > & master/nsmlog.log" '
376 subprocess.Popen(cmd, shell=
True)
382def stop_master(conffile):
383 masterhost = get_rfgetconf(conffile,
'master',
'ctlhost')
384 basedir = get_rfgetconf(conffile,
'system',
'execdir_base')
387 pidfile = basedir +
'/master/pid.data'
388 for pid
in open(pidfile,
'r'):
389 cmd =
'ssh ' + masterhost +
' "kill ' + pid +
'"'
391 p = subprocess.Popen(cmd, shell=
True)
395def start_rfarm_components(conffile):
396 run_eventprocessor(conffile)
397 run_outputserver(conffile)
398 run_eventserver(conffile)
399 run_dqmserver(conffile)
400 run_roisender(conffile)
405def stop_rfarm_components(conffile):
406 stop_roisender(conffile)
407 print(
"stop dqmserver")
408 stop_dqmserver(conffile)
410 stop_eventserver(conffile)
411 stop_outputserver(conffile)
417def start_rfarm_local(conffile):
418 start_rfarm_components(conffile)
424def stop_rfarm_local(conffile):
425 print(
"stopping eventprocessors")
426 stop_eventprocessor(conffile)
427 print(
"stopping rfarm components")
428 stop_rfarm_components(conffile)
429 print(
"stopping master")
430 stop_master(conffile)