7 # $Id: stopFrontend.py,v 1.10 2011/02/10 21:35:31 parag Exp $
10 # Stop a running glideinFrontend
19 import signal
,sys
,os
,os
.path
,fcntl
,string
,time
20 sys
.path
.append(os
.path
.join(sys
.path
[0],"../lib"))
21 import glideinFrontendPidLib
22 import glideinFrontendConfig
24 # this one should never throw an exeption
25 def get_element_pids(work_dir
,frontend_pid
):
27 frontendDescript
=glideinFrontendConfig
.FrontendDescript(work_dir
)
28 groups
=string
.split(frontendDescript
.data
['Groups'],',')
34 element_pid
,element_ppid
=glideinFrontendPidLib
.get_element_pid(work_dir
,group
)
35 except RuntimeError,e
:
37 continue # report error and go to next group
38 if element_ppid
!=frontend_pid
:
39 print "Group '%s' has an unexpected Parent PID: %s!=%s"%(group
,element_ppid
,frontend_pid
)
40 continue # report error and go to next group
41 element_pids
[group
]=element_pid
48 frontend_pid
=glideinFrontendPidLib
.get_frontend_pid(work_dir
)
49 except RuntimeError, e
:
54 element_pids
=get_element_pids(work_dir
,frontend_pid
)
57 element_keys
=element_pids
.keys()
61 # first soft kill the frontend (5s timeout)
62 os
.kill(frontend_pid
,signal
.SIGTERM
)
63 for retries
in range(25):
64 if glideinFrontendPidLib
.pidSupport
.check_pid(frontend_pid
):
69 # now check the elements (5s timeout)
71 for element
in element_keys
:
72 if glideinFrontendPidLib
.pidSupport
.check_pid(element_pids
[element
]):
73 #print "Element '%s' still alive, sending SIGTERM"%element
74 os
.kill(element_pids
[element
],signal
.SIGTERM
)
77 for retries
in range(25):
79 for element
in element_keys
:
80 if glideinFrontendPidLib
.pidSupport
.check_pid(element_pids
[element
]):
85 break # all elements dead
87 # final check for processes
88 if glideinFrontendPidLib
.pidSupport
.check_pid(frontend_pid
):
89 print "Hard killed frontend"
90 os
.kill(frontend_pid
,signal
.SIGKILL
)
91 for element
in element_keys
:
92 if glideinFrontendPidLib
.pidSupport
.check_pid(element_pids
[element
]):
93 print "Hard killed element '%s'"%element
94 os
.kill(element_pids
[element
],signal
.SIGKILL
)
98 if __name__
== '__main__':
100 print "Usage: stopFrontend.py work_dir"
103 sys
.exit(main(sys
.argv
[1]))