A new doc condor_config.html is being added showing the condor configuration
[burt-test.git] / frontend / stopFrontend.py
blob945429dc36d2344e2f45b334f0a9018be2b46097
1 #!/usr/bin/env python
3 # Project:
4 # glideinWMS
6 # File Version:
7 # $Id: stopFrontend.py,v 1.10 2011/02/10 21:35:31 parag Exp $
9 # Description:
10 # Stop a running glideinFrontend
12 # Arguments:
13 # $1 = work_dir
15 # Author:
16 # Igor Sfiligoi
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):
26 # get element pids
27 frontendDescript=glideinFrontendConfig.FrontendDescript(work_dir)
28 groups=string.split(frontendDescript.data['Groups'],',')
29 groups.sort()
31 element_pids={}
32 for group in groups:
33 try:
34 element_pid,element_ppid=glideinFrontendPidLib.get_element_pid(work_dir,group)
35 except RuntimeError,e:
36 print 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
43 return element_pids
45 def main(work_dir):
46 # get the pids
47 try:
48 frontend_pid=glideinFrontendPidLib.get_frontend_pid(work_dir)
49 except RuntimeError, e:
50 print e
51 return 1
52 #print frontend_pid
54 element_pids=get_element_pids(work_dir,frontend_pid)
55 #print element_pids
57 element_keys=element_pids.keys()
58 element_keys.sort()
60 # kill processes
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):
65 time.sleep(0.2)
66 else:
67 break # frontend dead
69 # now check the elements (5s timeout)
70 elements_alive=False
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)
75 elements_alive=True
76 if elements_alive:
77 for retries in range(25):
78 elements_alive=False
79 for element in element_keys:
80 if glideinFrontendPidLib.pidSupport.check_pid(element_pids[element]):
81 elements_alive=True
82 if elements_alive:
83 time.sleep(0.2)
84 else:
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)
95 return 0
98 if __name__ == '__main__':
99 if len(sys.argv)<2:
100 print "Usage: stopFrontend.py work_dir"
101 sys.exit(1)
103 sys.exit(main(sys.argv[1]))