3 # Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
4 # PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 import os, sys, pickle, signal, commands
24 def getPiDict(port,appname='salome',full=True):
25 from Utils_Identity import getShortHostName
27 host = os.getenv("HOSTNAME")
29 host = os.getenv("HOST")
31 host = getShortHostName()
34 filedict.append( os.getenv('USER') ) # user name
35 filedict.append( host ) # host name
36 filedict.append( str(port) ) # port number
37 filedict.append( appname.upper() ) # application name
38 filedict.append( 'pidict' ) # constant part
40 filedict = '_'.join(filedict)
42 filedict = os.getenv("HOME") + '/' + filedict
45 def appliCleanOmniOrbConfig(port):
47 remove omniorb config files related to the port in SALOME application:
48 - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_${NSPORT}.cfg
49 - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_last.cfg
50 the last is removed only if the link points to the first file.
52 from Utils_Identity import getShortHostName
53 appli=os.environ.get("APPLI")
55 #Run outside application context
58 home = os.environ['HOME']
59 home='%s/%s'%(home,appli)
60 hostname=getShortHostName()
61 omniorb_config = '%s/.omniORB_%s_%s.cfg'%(home,hostname, str(port))
62 last_running_config = '%s/.omniORB_%s_last.cfg'%(home, hostname)
63 if os.access(last_running_config,os.F_OK):
64 pointedPath = os.readlink(last_running_config)
65 if pointedPath[0] != '/':
66 pointedPath=os.path.join(os.path.dirname(last_running_config), pointedPath)
67 if pointedPath == omniorb_config:
68 os.unlink(last_running_config)
71 if os.access(omniorb_config,os.F_OK):
72 os.remove(omniorb_config)
76 ########## kills all salome processes with the given port ##########
79 filedict=getPiDict(port)
82 fpid=open(filedict, 'r')
85 print "file %s giving SALOME process id is not readable"% filedict
89 cmd = 'pid=`ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'"` ; echo $pid > /tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log'
92 fpidomniNames=open('/tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log')
93 prc = fpidomniNames.read()
96 for field in prc.split(" ") :
97 if field == "omniNames" :
98 if pidfield != "egrep" :
99 print 'stop process '+pidfield+' : omniNames'
100 os.system('kill -9 '+pidfield)
106 process_ids=pickle.load(fpid)
108 for process_id in process_ids:
110 for pid, cmd in process_id.items():
111 print "stop process %s : %s"% (pid, cmd[0])
113 os.kill(int(pid),signal.SIGKILL)
115 print " ------------------ process %s : %s not found"% (pid, cmd[0])
122 cmd='ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'" | sed -e "s%[^0-9]*\([0-9]*\) .*%\\1%g"'
123 pid = commands.getoutput(cmd)
125 while pid != "" and len(a.split(" ")) < 2:
126 a = commands.getoutput("pid=`ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"`; kill -9 $pid")
127 pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
132 appliCleanOmniOrbConfig(port)
136 if __name__ == "__main__":
137 for port in sys.argv[1:]: