From 32bcc091ac41cf2c7be027d2736932c7bc96dca0 Mon Sep 17 00:00:00 2001 From: prascle Date: Tue, 29 Nov 2005 18:22:51 +0000 Subject: [PATCH] PR: Application scripts improvement --- Makefile.in | 3 +- bin/NSparam.py | 69 +++++++++++++++++++++++++++++++++ bin/appliskel/README | 24 +++++++++--- bin/appliskel/killCurrentPort | 35 +++++++++++++++++ bin/appliskel/runAppli | 58 +++------------------------ bin/appliskel/runConsole | 18 ++------- bin/appliskel/runParam | 5 ++- bin/appliskel/runRemote.sh | 18 ++------- bin/appliskel/runSession | 31 +++++++-------- bin/appliskel/runTests | 18 ++------- bin/appliskel/searchFreePort.sh | 37 ++++++++++++++++++ bin/appliskel/setAppliPath.sh | 17 ++++++++ 12 files changed, 211 insertions(+), 122 deletions(-) create mode 100755 bin/NSparam.py create mode 100755 bin/appliskel/killCurrentPort create mode 100755 bin/appliskel/searchFreePort.sh create mode 100755 bin/appliskel/setAppliPath.sh diff --git a/Makefile.in b/Makefile.in index 85ffaf022..42dedf940 100644 --- a/Makefile.in +++ b/Makefile.in @@ -41,7 +41,8 @@ salome.launch \ envSalome.py \ salomeConsole.py \ showNS.py \ -addToKillList.py +addToKillList.py \ +NSparam.py # copy header files in common directory OWN_CONFIG_H=@OWN_CONFIG_H@ diff --git a/bin/NSparam.py b/bin/NSparam.py new file mode 100755 index 000000000..721c6a0f9 --- /dev/null +++ b/bin/NSparam.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +import sys,os +import string + +def getNSparams(info=""): + """ + check environment for omniORB configuration file. + parse the file to find the line defining naming service host and port, + set environment variables NSPORT and NSHOST, + get host and port, + if info==host print host + elif info==port print host + else print 2 strings on stdout on one line: host port + """ + my_port="" + my_host="" + if os.environ.has_key("OMNIORB_CONFIG"): + file = open(os.environ["OMNIORB_CONFIG"], "r") + s = file.read() + while len(s): + l = string.split(s, ":") + if string.split(l[0], " ")[0] == "ORBInitRef" or \ + string.split(l[0], " ")[0] == "InitRef" : + my_port = l[len(l)-1] + if my_port[-1] == '\n': + my_port = my_port[:-1] + pass + my_host = l[len(l)-2] + break; + pass + s = file.read() + pass + pass + if info=='host': + # keep print, stdout used in shell + print my_host + os.environ['NSHOST']=my_host + return my_host + pass + elif info=='port': + # keep print, stdout used in shell + print my_port + os.environ['NSPORT']=my_port + return my_port + pass + else: + # keep print, stdout used in shell + print my_host, my_port + return my_host, my_port + pass + +# ------------------------------------------------------------------------ + +if __name__ == "__main__": + if len(sys.argv) >1: + if sys.argv[1]=='host': + getNSparams('host') + pass + elif sys.argv[1]=='port': + getNSparams('port') + pass + else: + getNSparams('') + pass + pass + else: + getNSparams('') + pass diff --git a/bin/appliskel/README b/bin/appliskel/README index e54cc886b..f3f283cb8 100644 --- a/bin/appliskel/README +++ b/bin/appliskel/README @@ -17,13 +17,13 @@ SALOME Application concept See SALOME_Application_ to define your own configuration of SALOME and run it on one or several computers. This is the recommended way of configuration. -.. _SALOME_Application: ./doc/SALOME_Application.html +.. _SALOME_Application: ../../doc/SALOME_Application.html User run scripts ---------------- -The SALOME user can use 4 scripts: +The SALOME user can use the following scripts: runAppli Launches a SALOME Session @@ -41,10 +41,15 @@ runConsole It is also possible to use runSession, then python. runTests - Similar to runSession, used for unit testing. runSession tries to use an - already existing naming service definition from a running session (hostname - and port number), runTests defines a new configuration for naming service - (new port number). + Similar to runSession, used for unit testing. runTests defines a new + configuration for naming service (new port number) to avoid interferences + with a running SALOME session. runSession tries to use an already existing + naming service definition from a running session (hostname & port number). + +killCurrentPort + Kills the last SALOME session corresponding to this application, and + intially launched from this computer. + Cleans associated config files. SALOME internal run scripts --------------------------- @@ -52,6 +57,12 @@ SALOME internal run scripts envd Sets SALOME application environment, envd is sourced by other scripts. +setAppliPath.sh + Used by other scripts to define the Application Path. + +searchFreePort.sh + Used by other scripts to find a free port for naming service. + For remote calls, SALOME uses one script. runRemote.sh @@ -59,6 +70,7 @@ runRemote.sh define the hostname and port userd for naming service, the remaining arguments define the command to execute. + The following files must be adapted to your environment and SALOME Application ------------------------------------------------------------------------------ diff --git a/bin/appliskel/killCurrentPort b/bin/appliskel/killCurrentPort new file mode 100755 index 000000000..bca506068 --- /dev/null +++ b/bin/appliskel/killCurrentPort @@ -0,0 +1,35 @@ +#!/bin/bash + +# --- retrieve APPLI path, relative to $HOME, set ${APPLI} + +. `dirname $0`/setAppliPath.sh + +# --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...) + +. ${HOME}/${APPLI}/envd ${HOME}/${APPLI} + +# --- find omniORB configuration relative to current session if any + +myhost=`hostname` +fileOmniConfig=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg + +if [ -f $fileOmniConfig ]; then + export OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg +fi + +currentPort=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py port` +echo $currentPort + +# --- kill current salome session + +${KERNEL_ROOT_DIR}/bin/salome/killSalomeWithPort.py $currentPort + +# --- delete config files + +if [ -s $fileOmniConfig ]; then + refConfig=`ls -l $fileOmniConfig | awk '{print \$NF}'` + if [ -f $refConfig ]; then + rm $refConfig + fi + rm $fileOmniConfig +fi diff --git a/bin/appliskel/runAppli b/bin/appliskel/runAppli index 700e669d4..1d86ad3d5 100755 --- a/bin/appliskel/runAppli +++ b/bin/appliskel/runAppli @@ -1,20 +1,8 @@ #!/bin/bash -# --- retrieve APPLI path, relative to $HOME -# on sarge, "which" gives not allways the absolute path... - -comName=`which $0` -aa=${comName:0:1} -if test x$aa == x\/; then - mycom=${comName} -elif test x$aa == x\.; then - mycom=${PWD}/${comName:2} -else - mycom=${PWD}/${comName} -fi -APPLI=`echo ${HOME} \`dirname $mycom\` | awk ' { print substr($2,length($1)+2) } '` -#echo $APPLI -export APPLI +# --- retrieve APPLI path, relative to $HOME, set ${APPLI} + +. `dirname $0`/setAppliPath.sh # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...) @@ -22,38 +10,8 @@ export APPLI # --- define port for CORBA naming service -searchFreePort() { - echo -n "Searching for a free port for naming service: " - export NSPORT=2810 - local limit=$NSPORT - let limit=limit+100 - while [ 1 ] - do - aRes=`netstat -ltn | grep -E :${NSPORT}` - if [ -z "$aRes" ]; then - echo ${NSPORT} - Ok - local myhost=`hostname` - export OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_${NSPORT}.cfg - export NSPORT - export NSHOST=${myhost} - local initref="NameService=corbaname::"`hostname`":$NSPORT" - #echo "ORBInitRef $initref" > $OMNIORB_CONFIG - echo "InitRef = $initref" > $OMNIORB_CONFIG - export LAST_RUNNING_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg - rm ${LAST_RUNNING_CONFIG} - ln -s ${OMNIORB_CONFIG} ${LAST_RUNNING_CONFIG} - break - fi - echo -n "${NSPORT} " - if [[ $NSPORT -eq $limit ]] ; then - echo - echo "Can't find a free port to launch omniNames" - echo "Try to kill the running servers and then launch SALOME again." - exit - fi - let NSPORT=NSPORT+1 - done -} +. `dirname $0`/searchFreePort.sh +searchFreePort # --- if mpi lam, start lam (seems safe to be done several times) # arret manuel avec lamhalt @@ -66,13 +24,9 @@ fi # (default arguments defined in local salome.launch could be completed # by arguments to this command) -searchFreePort - if [ $# -ne 0 ] ; then ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python -i ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py $* - # --- todo delete omniORB config files in relation to the naming service kill - rm ${OMNIORB_CONFIG} - rm ${LAST_RUNNING_CONFIG} + else ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py fi diff --git a/bin/appliskel/runConsole b/bin/appliskel/runConsole index e45f58611..caeabbdd6 100755 --- a/bin/appliskel/runConsole +++ b/bin/appliskel/runConsole @@ -1,20 +1,8 @@ #!/bin/bash -# --- retrieve APPLI path, relative to $HOME -# on sarge, "which" gives not allways the absolute path... - -comName=`which $0` -aa=${comName:0:1} -if test x$aa == x\/; then - mycom=${comName} -elif test x$aa == x\.; then - mycom=${PWD}/${comName:2} -else - mycom=${PWD}/${comName} -fi -APPLI=`echo ${HOME} \`dirname $mycom\` | awk ' { print substr($2,length($1)+2) } '` -#echo $APPLI -export APPLI +# --- retrieve APPLI path, relative to $HOME, set ${APPLI} + +. `dirname $0`/setAppliPath.sh # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...) diff --git a/bin/appliskel/runParam b/bin/appliskel/runParam index 17bbd618b..c858c670f 100755 --- a/bin/appliskel/runParam +++ b/bin/appliskel/runParam @@ -1,5 +1,6 @@ #!/bin/bash -./runAppli --killall +./KillCurrentPort + +./runAppli --logger -#./runSession killSalome.py diff --git a/bin/appliskel/runRemote.sh b/bin/appliskel/runRemote.sh index d3297a6c5..594616a07 100755 --- a/bin/appliskel/runRemote.sh +++ b/bin/appliskel/runRemote.sh @@ -21,21 +21,9 @@ # $3 and following : local command to execute, with args # -# --- retrieve APPLI path, relative to $HOME -# on sarge, "which" gives not allways the absolute path... - -comName=`which $0` -aa=${comName:0:1} -if test x$aa == x\/; then - mycom=${comName} -elif test x$aa == x\.; then - mycom=${PWD}/${comName:2} -else - mycom=${PWD}/${comName} -fi -APPLI=`echo ${HOME} \`dirname $mycom\` | awk ' { print substr($2,length($1)+2) } '` -#echo $APPLI -export APPLI +# --- retrieve APPLI path, relative to $HOME, set ${APPLI} + +. `dirname $0`/setAppliPath.sh # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...) diff --git a/bin/appliskel/runSession b/bin/appliskel/runSession index 2ab579ce6..22d3fdd0f 100755 --- a/bin/appliskel/runSession +++ b/bin/appliskel/runSession @@ -5,28 +5,27 @@ # Use it without args to run an interactive shell under Salome env # -# --- retrieve APPLI path, relative to $HOME -# on sarge, "which" gives not allways the absolute path... - -comName=`which $0` -aa=${comName:0:1} -if test x$aa == x\/; then - mycom=${comName} -elif test x$aa == x\.; then - mycom=${PWD}/${comName:2} -else - mycom=${PWD}/${comName} -fi -APPLI=`echo ${HOME} \`dirname $mycom\` | awk ' { print substr($2,length($1)+2) } '` -echo $APPLI -export APPLI +# --- retrieve APPLI path, relative to $HOME, set ${APPLI} + +. `dirname $0`/setAppliPath.sh # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...) . ${HOME}/${APPLI}/envd ${HOME}/${APPLI} +# --- set omniORB configuration to current session if any + myhost=`hostname` -export OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg +fileOmniConfig=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg + +if [ -f $fileOmniConfig ]; then + export OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg + + # --- set environment variables for port and hostname of NamingService + + export NSHOST=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py host` + export NSPORT=`${KERNEL_ROOT_DIR}/bin/salome/NSparam.py port` +fi # --- invoque shell with or without args diff --git a/bin/appliskel/runTests b/bin/appliskel/runTests index 6e625f0a0..755825d79 100755 --- a/bin/appliskel/runTests +++ b/bin/appliskel/runTests @@ -1,20 +1,8 @@ #!/bin/bash -# --- retrieve APPLI path, relative to $HOME -# on sarge, "which" gives not allways the absolute path... - -comName=`which $0` -aa=${comName:0:1} -if test x$aa == x\/; then - mycom=${comName} -elif test x$aa == x\.; then - mycom=${PWD}/${comName:2} -else - mycom=${PWD}/${comName} -fi -APPLI=`echo ${HOME} \`dirname $mycom\` | awk ' { print substr($2,length($1)+2) } '` -#echo $APPLI -export APPLI +# --- retrieve APPLI path, relative to $HOME, set ${APPLI} + +. `dirname $0`/setAppliPath.sh # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...) diff --git a/bin/appliskel/searchFreePort.sh b/bin/appliskel/searchFreePort.sh new file mode 100755 index 000000000..8108a93dc --- /dev/null +++ b/bin/appliskel/searchFreePort.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# --- define port for CORBA naming service + +searchFreePort() { + echo -n "Searching for a free port for naming service: " + export NSPORT=2810 + local limit=$NSPORT + let limit=limit+100 + while [ 1 ] + do + aRes=`netstat -ltn | grep -E :${NSPORT}` + if [ -z "$aRes" ]; then + echo ${NSPORT} - Ok + local myhost=`hostname` + export OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_${NSPORT}.cfg + export NSPORT + export NSHOST=${myhost} + local initref="NameService=corbaname::"`hostname`":$NSPORT" + #echo "ORBInitRef $initref" > $OMNIORB_CONFIG + echo "InitRef = $initref" > $OMNIORB_CONFIG + export LAST_RUNNING_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg + rm ${LAST_RUNNING_CONFIG} + ln -s ${OMNIORB_CONFIG} ${LAST_RUNNING_CONFIG} + break + fi + echo -n "${NSPORT} " + if [[ $NSPORT -eq $limit ]] ; then + echo + echo "Can't find a free port to launch omniNames" + echo "Try to kill the running servers and then launch SALOME again." + exit + fi + let NSPORT=NSPORT+1 + done +} + diff --git a/bin/appliskel/setAppliPath.sh b/bin/appliskel/setAppliPath.sh new file mode 100755 index 000000000..d9361ae52 --- /dev/null +++ b/bin/appliskel/setAppliPath.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# --- retrieve APPLI path, relative to $HOME, set ${APPLI} +# on sarge, "which" gives not allways the absolute path... + +comName=`which $0` +aa=${comName:0:1} +if test x$aa == x\/; then + mycom=${comName} +elif test x$aa == x\.; then + mycom=${PWD}/${comName:2} +else + mycom=${PWD}/${comName} +fi +APPLI=`echo ${HOME} \`dirname $mycom\` | awk ' { print substr($2,length($1)+2) } '` +#echo $APPLI +export APPLI -- 2.39.2