Salome HOME
PR: merge from branch BR_UT_V310a2 tag BR_UT_V310a2_20051115
[modules/kernel.git] / bin / appliskel / runAppli
1 #!/bin/bash
2
3 # --- retrieve APPLI path, relative to $HOME
4 #     on sarge, "which" gives not allways the absolute path...
5      
6 comName=`which $0`
7 aa=${comName:0:1}
8 if test x$aa == x\/; then
9   mycom=${comName}
10 elif test x$aa == x\.; then
11   mycom=${PWD}/${comName:2}
12 else
13   mycom=${PWD}/${comName}
14 fi
15 APPLI=`echo ${HOME} \`dirname $mycom\` | awk ' { print substr($2,length($1)+2) } '`
16 #echo $APPLI
17 export APPLI
18
19 # --- set the SALOME environment (prerequisites, MODULES_ROOT_DIR...)
20
21 . ${HOME}/${APPLI}/envd ${HOME}/${APPLI}
22
23 # --- define port for CORBA naming service
24
25 searchFreePort() {
26     echo -n "Searching for a free port for naming service: "
27     export NSPORT=2810
28     local limit=$NSPORT
29     let limit=limit+100
30     while [ 1 ]
31     do
32         aRes=`netstat -ltn | grep -E :${NSPORT}`
33         if [ -z "$aRes" ]; then
34             echo ${NSPORT} - Ok
35             local myhost=`hostname`
36             export OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_${NSPORT}.cfg
37             export NSPORT
38             export NSHOST=${myhost}
39             local initref="NameService=corbaname::"`hostname`":$NSPORT"
40             #echo "ORBInitRef $initref" > $OMNIORB_CONFIG
41             echo "InitRef = $initref" > $OMNIORB_CONFIG
42             export LAST_RUNNING_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_last.cfg
43             rm ${LAST_RUNNING_CONFIG}
44             ln -s ${OMNIORB_CONFIG} ${LAST_RUNNING_CONFIG}
45             break
46         fi
47         echo -n "${NSPORT} "
48         if [[ $NSPORT -eq $limit ]] ; then
49             echo
50             echo "Can't find a free port to launch omniNames"
51             echo "Try to kill the running servers and then launch SALOME again."
52             exit
53         fi
54         let NSPORT=NSPORT+1
55     done
56 }
57
58 # --- if mpi lam, start lam (seems safe to be done several times)
59 #     arret manuel avec lamhalt
60
61 if [ "$LAMBHOST" ]; then
62   lamboot
63 fi
64
65 # --- run SALOME
66 #    (default arguments defined in local salome.launch could be completed
67 #     by arguments to this command)
68
69 searchFreePort
70
71 if [ $# -ne 0 ] ; then
72     ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python -i ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py $*
73     # --- todo delete omniORB config files in relation to the naming service kill
74     rm ${OMNIORB_CONFIG}
75     rm ${LAST_RUNNING_CONFIG}
76 else
77     ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py 
78 fi