Back to index

salome-kernel  6.5.0
Functions | Variables
killSalomeWithPort Namespace Reference

Functions

def getPiDict
def appliCleanOmniOrbConfig
def shutdownMyPort
 kills all salome processes with the given port ##########
def killMyPort
def killNotifdAndClean
def killMyPortSpy

Variables

list pid = sys.argv[2]
list port = sys.argv[3]

Function Documentation

Remove omniorb config files related to the port in SALOME application:
- ${HOME}/${APPLI}/USERS/.omniORB_${USER}_${HOSTNAME}_${NSPORT}.cfg
- ${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg
the last is removed only if the link points to the first file.

Definition at line 82 of file killSalomeWithPort.py.

00082 
00083 def appliCleanOmniOrbConfig(port):
00084     """
00085     Remove omniorb config files related to the port in SALOME application:
00086     - ${HOME}/${APPLI}/USERS/.omniORB_${USER}_${HOSTNAME}_${NSPORT}.cfg
00087     - ${HOME}/${APPLI}/USERS/.omniORB_${USER}_last.cfg
00088     the last is removed only if the link points to the first file.
00089     """
00090     from salome_utils import generateFileName, getUserName
00091     home  = os.getenv("HOME")
00092     appli = os.getenv("APPLI")
00093     if appli is None:
00094         #Run outside application context
00095         pass
00096     else:
00097         dir = os.path.join(home, appli,"USERS")
00098         omniorb_config      = generateFileName(dir, prefix="omniORB",
00099                                                extension="cfg",
00100                                                hidden=True,
00101                                                with_username=True,
00102                                                with_hostname=True,
00103                                                with_port=port)
00104         last_running_config = generateFileName(dir, prefix="omniORB",
00105                                                with_username=True,
00106                                                suffix="last",
00107                                                extension="cfg",
00108                                                hidden=True)
00109         if os.access(last_running_config,os.F_OK):
00110             pointedPath = os.readlink(last_running_config)
00111             if pointedPath[0] != '/':
00112                 pointedPath=os.path.join(os.path.dirname(last_running_config), pointedPath)
00113             if pointedPath == omniorb_config:
00114                 os.unlink(last_running_config)
00115                 pass
00116             pass
00117         if os.access(omniorb_config,os.F_OK):
00118             os.remove(omniorb_config)
00119             pass
00120 
00121         if os.path.lexists(last_running_config):return 
00122 
00123         #try to relink last.cfg to an existing config file if any
00124         files = glob.glob(os.path.join(os.environ["HOME"],Utils_Identity.getapplipath(),
00125                                        "USERS",".omniORB_"+getUserName()+"_*.cfg"))
00126         current_config=None
00127         current=0
00128         for f in files:
00129           stat=os.stat(f)
00130           if stat.st_atime > current:
00131             current=stat.st_atime
00132             current_config=f
00133         if current_config:
00134           os.symlink(os.path.normpath(current_config), last_running_config)
00135 
00136         pass
00137     pass

Here is the call graph for this function:

Here is the caller graph for this function:

def killSalomeWithPort.getPiDict (   port,
  appname = 'salome',
  full = True,
  hidden = True,
  hostname = None 
)
Get file with list of SALOME processes.
This file is located in the user's home directory
and named .<user>_<host>_<port>_SALOME_pidict
where
<user> is user name
<host> is host name
<port> is port number

Parameters:
- port    : port number
- appname : application name (default is 'SALOME')
- full    : if True, full path to the file is returned, otherwise only file name is returned
- hidden  : if True, file name is prefixed with . (dot) symbol; this internal parameter is used
to support compatibility with older versions of SALOME

Definition at line 39 of file killSalomeWithPort.py.

00039 
00040 def getPiDict(port,appname='salome',full=True,hidden=True,hostname=None):
00041     """
00042     Get file with list of SALOME processes.
00043     This file is located in the user's home directory
00044     and named .<user>_<host>_<port>_SALOME_pidict
00045     where
00046     <user> is user name
00047     <host> is host name
00048     <port> is port number
00049 
00050     Parameters:
00051     - port    : port number
00052     - appname : application name (default is 'SALOME')
00053     - full    : if True, full path to the file is returned, otherwise only file name is returned
00054     - hidden  : if True, file name is prefixed with . (dot) symbol; this internal parameter is used
00055     to support compatibility with older versions of SALOME
00056     """
00057     from salome_utils import generateFileName, getTmpDir
00058     dir = ""
00059     if not hostname:
00060         hostname = os.getenv("NSHOST")
00061         if hostname: hostname = hostname.split(".")[0]
00062         pass
00063     if full:
00064         # full path to the pidict file is requested
00065         if hidden:
00066             # new-style dot-prefixed pidict files
00067             # are in the system-dependant temporary diretory
00068             dir = getTmpDir()
00069         else:
00070             # old-style non-dot-prefixed pidict files
00071             # are in the user's home directory
00072             dir = os.getenv("HOME")
00073             pass
00074         pass
00075     return generateFileName(dir,
00076                             suffix="pidict",
00077                             hidden=hidden,
00078                             with_username=True,
00079                             with_hostname=hostname or True,
00080                             with_port=port,
00081                             with_app=appname.upper())

Here is the call graph for this function:

Here is the caller graph for this function:

Kill SALOME session running on the specified port.
Parameters:
- port - port number

Definition at line 181 of file killSalomeWithPort.py.

00181 
00182 def killMyPort(port):
00183     """
00184     Kill SALOME session running on the specified port.
00185     Parameters:
00186     - port - port number
00187     """
00188     from salome_utils import getShortHostName, getHostName
00189     
00190     # try to shutdown session nomally
00191     import threading, time
00192     threading.Thread(target=shutdownMyPort, args=(port,)).start()
00193     time.sleep(3) # wait a little, then kill processes (should be done if shutdown procedure hangs up)
00194     
00195     # new-style dot-prefixed pidict file
00196     filedict = getPiDict(port, hidden=True)
00197     # provide compatibility with old-style pidict file (not dot-prefixed)
00198     if not os.path.exists(filedict): filedict = getPiDict(port, hidden=False)
00199     # provide compatibility with old-style pidict file (short hostname)
00200     if not os.path.exists(filedict): filedict = getPiDict(port, hidden=True,  hostname=getShortHostName())
00201     # provide compatibility with old-style pidict file (not dot-prefixed, short hostname)
00202     if not os.path.exists(filedict): filedict = getPiDict(port, hidden=False, hostname=getShortHostName())
00203     # provide compatibility with old-style pidict file (long hostname)
00204     if not os.path.exists(filedict): filedict = getPiDict(port, hidden=True,  hostname=getHostName())
00205     # provide compatibility with old-style pidict file (not dot-prefixed, long hostname)
00206     if not os.path.exists(filedict): filedict = getPiDict(port, hidden=False, hostname=getHostName())
00207     #
00208     try:
00209         fpid = open(filedict, 'r')
00210         #
00211         from salome_utils import generateFileName
00212         if sys.platform == "win32":
00213             username = os.getenv( "USERNAME" )
00214         else:
00215             username = os.getenv('USER')
00216         path = os.path.join('/tmp/logs', username)
00217         fpidomniNames = generateFileName(path,
00218                                          prefix="",
00219                                          suffix="Pid_omniNames",
00220                                          extension="log",
00221                                          with_port=port)
00222         if not sys.platform == 'win32':        
00223             cmd = 'pid=`ps -eo pid,command | egrep "[0-9] omniNames -start %s"` ; echo $pid > %s' % ( str(port), fpidomniNames )
00224             a = os.system(cmd)
00225             pass
00226         try:
00227             fpidomniNamesFile = open(fpidomniNames)
00228             lines = fpidomniNamesFile.readlines()
00229             fpidomniNamesFile.close()
00230             os.remove(fpidomniNames)
00231             for l in lines:
00232                 try:
00233                     pidfield = l.split()[0] # pid should be at the first position
00234                     if sys.platform == "win32":
00235                         import win32pm
00236                         if verbose(): print 'stop process '+pidfield+' : omniNames'
00237                         win32pm.killpid(int(pidfield),0)
00238                     else:
00239                         if verbose(): print 'stop process '+pidfield+' : omniNames'
00240                         os.kill(int(pidfield),signal.SIGKILL)
00241                         pass
00242                     pass
00243                 except:
00244                     pass
00245                 pass
00246             pass
00247         except:
00248             pass
00249         #
00250         try:
00251             process_ids=pickle.load(fpid)
00252             fpid.close()
00253             for process_id in process_ids:
00254                 for pid, cmd in process_id.items():
00255                     if verbose(): print "stop process %s : %s"% (pid, cmd[0])
00256                     try:
00257                         if sys.platform == "win32":
00258                             import win32pm
00259                             win32pm.killpid(int(pid),0)                            
00260                         else:
00261                             os.kill(int(pid),signal.SIGKILL)
00262                             pass
00263                         pass
00264                     except:
00265                         if verbose(): print "  ------------------ process %s : %s not found"% (pid, cmd[0])
00266                         pass
00267                     pass # for pid, cmd ...
00268                 pass # for process_id ...
00269             pass # try...
00270         except:
00271             pass
00272         #
00273         os.remove(filedict)
00274         cmd='ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'" | sed -e "s%[^0-9]*\([0-9]*\) .*%\\1%g"'
00275         pid = commands.getoutput(cmd)
00276         a = ""
00277         while pid and len(a.split()) < 2:
00278             a = commands.getoutput("kill -9 " + pid)
00279             pid = commands.getoutput(cmd)
00280             #print pid
00281             pass
00282         pass
00283     except:
00284         print "Cannot find or open SALOME PIDs file for port", port
00285         pass
00286     #
00287     appliCleanOmniOrbConfig(port)
00288     pass
            

Here is the call graph for this function:

Here is the caller graph for this function:

def killSalomeWithPort.killMyPortSpy (   pid,
  port 
)

Definition at line 312 of file killSalomeWithPort.py.

00312 
00313 def killMyPortSpy(pid, port):
00314     dt = 1.0
00315     while 1:
00316         if sys.platform == "win32":
00317             from win32pm import killpid
00318             if killpid(int(pid), 0) != 0:
00319                 return
00320         else:
00321             from os import kill
00322             try:
00323                 kill(int(pid), 0)
00324             except OSError, e:
00325                 if e.errno != 3:
00326                     return
00327                 break
00328             pass
00329         from time import sleep
00330         sleep(dt)
00331         pass
00332     filedict = getPiDict(port, hidden=True)
00333     if not os.path.exists(filedict):
00334         return
00335     try:
00336         import omniORB
00337         orb = omniORB.CORBA.ORB_init(sys.argv, omniORB.CORBA.ORB_ID)
00338         import SALOME_NamingServicePy
00339         ns = SALOME_NamingServicePy.SALOME_NamingServicePy_i(orb)
00340         import SALOME
00341         session = ns.Resolve("/Kernel/Session")
00342         assert session
00343     except:
00344         return
00345     try:
00346         status = session.GetStatSession()
00347     except:
00348         # -- session is in naming service but has crash
00349         status = None
00350         pass
00351     if status:
00352         if not status.activeGUI:
00353             return
00354         pass
00355     killMyPort(port)
00356     return

Here is the call graph for this function:

Kill notifd daemon and clean application running on the specified port.
Parameters:
- port - port number

Definition at line 289 of file killSalomeWithPort.py.

00289 
00290 def killNotifdAndClean(port):
00291     """
00292     Kill notifd daemon and clean application running on the specified port.
00293     Parameters:
00294     - port - port number
00295     """
00296     try:
00297       filedict=getPiDict(port)
00298       f=open(filedict, 'r')
00299       pids=pickle.load(f)
00300       for d in pids:
00301         for pid,process in d.items():
00302           if 'notifd' in process:
00303             cmd='kill -9 %d'% pid
00304             os.system(cmd)
00305       os.remove(filedict)
00306     except:
00307       #import traceback
00308       #traceback.print_exc()
00309       pass
00310 
00311     appliCleanOmniOrbConfig(port)

Here is the call graph for this function:

kills all salome processes with the given port ##########

Shutdown SALOME session running on the specified port.
Parameters:
- port - port number

Definition at line 140 of file killSalomeWithPort.py.

00140 
00141 def shutdownMyPort(port):
00142     """
00143     Shutdown SALOME session running on the specified port.
00144     Parameters:
00145     - port - port number
00146     """
00147     if not port: return
00148     
00149     from salome_utils import generateFileName
00150 
00151     # set OMNIORB_CONFIG variable to the proper file
00152     home  = os.getenv("HOME")
00153     appli = os.getenv("APPLI")
00154     kwargs = {}
00155     if appli is not None: 
00156         home = os.path.join(home, appli,"USERS")
00157         kwargs["with_username"]=True
00158         pass
00159     omniorb_config = generateFileName(home, prefix="omniORB",
00160                                       extension="cfg",
00161                                       hidden=True,
00162                                       with_hostname=True,
00163                                       with_port=port,
00164                                       **kwargs)
00165     os.environ['OMNIORB_CONFIG'] = omniorb_config
00166 
00167     # give the chance to the servers to shutdown properly
00168     try:
00169         import time
00170         import salome_kernel
00171         orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init()
00172         # shutdown all
00173         lcc.shutdownServers()
00174         # give some time to shutdown to complete
00175         time.sleep(1)
00176         # shutdown omniNames and notifd
00177         salome_kernel.LifeCycleCORBA.killOmniNames()
00178     except:
00179         pass
00180     pass
    

Here is the call graph for this function:


Variable Documentation

list killSalomeWithPort.pid = sys.argv[2]

Definition at line 359 of file killSalomeWithPort.py.

list killSalomeWithPort.port = sys.argv[3]

Definition at line 360 of file killSalomeWithPort.py.