Testing library separation: now not in launcher but isolated
[anna.git] / example / diameter / launcher / DEPLOY.sh
1 #!/bin/bash
2
3 #############
4 # VARIABLES #
5 #############
6 SETUPS_DIR=../../../source/diameter/stack/setups
7 MSGDTD=../../../include/anna/diameter/codec/message.dtd
8 DCTDTD=../../../include/anna/diameter/stack/dictionary.dtd
9 SERVICES=./resources/services_examples
10 STACK_EXAMPLES=./resources/stack_examples
11 SRVDTD=$SERVICES/services.dtd
12
13 # Executables in priority order:
14 EXEC_installed=/opt/bin/anna/example_diameter_launcher
15 EXECS=( $EXEC_installed ./release/example_diameter_launcher ./debug/example_diameter_launcher )
16
17 # Stack management
18 STACKMGMT_EXEC_installed=/opt/bin/anna/example_diameter_stackManagement
19 STACKMGMT_EXECS=( $STACKMGMT_EXEC_installed ../stackManagement/release/example_diameter_stackManagement ../stackManagement/debug/example_diameter_stackManagement )
20
21 # Dynamic library:
22 #DYNLIB_installed=/usr/local/lib/libanna_dynamicLauncherProcedure.so
23 #DYNLIBS=( $DYNLIB_installed ../../../dynamic/launcher/default/release/libanna_dynamicLauncherProcedure.so ../../../dynamic/launcher/default/debug/libanna_dynamicLauncherProcedure.so )
24
25 #############
26 # FUNCTIONS #
27 #############
28 _exit () {
29    echo
30    echo $1
31    echo
32    exit 1
33 }
34
35 usage () {
36   echo "Usage: $0 [deployment_type: a|b|f|s] [deployment_path]"
37   echo
38   echo "       deployment_type:"
39   echo "          a=advanced"
40   echo "          b=basic"
41   echo "          f=function test client"
42   echo "          s=system test client"
43   echo "       deployment_path:"
44   echo "          non-existent path directory."
45   echo
46   echo "       For example:"
47   echo "          $0 b $HOME/ADML-basicServer"
48   echo "          $0 b $HOME/ADML-MMSbalancer"
49   echo "          $0 f $HOME/ADML-tester"
50   echo "          $0 s $HOME/ADML-stress-client"
51   echo
52   exit 0
53 }
54  
55 # $1: deployment type
56 createRunScript () {
57   # Basic launcher 'run.sh' will be created at deployment configuration: 
58   [ "$1" = "b" ] && return
59
60   local other=
61   [ "$1" = "a" ] && other="--httpServer \`grep -v ^# .httpServer\`"
62   [ "$1" = "f" ] && ln -s ADML-launcher $EXE
63   [ "$1" = "s" ] && { other="--disableLogs"; ln -s ADML-launcher $EXE ; }
64
65   echo "Creating 'run.sh' script ..."
66
67   cat << EOF > run.sh
68 #!/bin/bash
69 cd \`dirname \$0\`
70 EXE=$EXE
71 STARTED=\`pgrep \$EXE$ 2>/dev/null\`
72 [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
73 ./pre-start.sh
74 0> launcher.trace
75 rm -f counters/* test-reports/*
76 # Execution line:
77 export LD_LIBRARY_PATH=\$PWD/dynlibs
78 ./\$EXE --services services.xml --cntDir counters --tmDir test-reports $other &
79 echo \$! > .pid
80 EOF
81
82   chmod a+x run.sh
83 }
84
85 #############
86 # EXECUTION #
87 #############
88 cd `dirname $0`
89 echo
90 echo "---------------------------------------"
91 echo "Anna Diameter Launcher (ADML) deployment"
92 echo "---------------------------------------"
93 [ "$1" = "--help" -o "$1" = "-h" ] && usage
94 echo " (--help or -h for more info)"
95 echo
96 echo "Basic checkings ..."
97
98 # Launcher executable:
99 available=
100 for EXEC in ${EXECS[@]}; do
101   echo -n "Looking executable at '$EXEC' ... "
102   [ -x $EXEC ] && { available=yes ; echo "available !" ; break ; }
103   echo "not found"
104 done
105 [ -z "$available" ] && _exit "Anna Diameter Launcher (ADML) is not installed neither linked. See README.md (Install section)."
106
107 # Dynamic library variant:
108 dynlib_variant=
109 [ -f ./release/example_diameter_launcher ] && dynlib_variant=release
110 [ -f ./debug/example_diameter_launcher ] && dynlib_variant=debug
111 [ -z "$dynlib_variant" ] && _exit "Unknown dynamic library variant"
112
113 # Dictionary creation:
114 available=
115 for STACKMGMT_EXEC in ${STACKMGMT_EXECS[@]}; do
116   echo -n "Looking stack management executable at '$STACKMGMT_EXEC' ... "
117   [ -x $STACKMGMT_EXEC ] && { available=yes ; echo "available !" ; break ; }
118   echo "not found"
119 done
120 [ -z "$available" ] && _exit "Anna Diameter Stack Management Tool is not installed neither linked. See README.md (Install section)."
121 STACKMGMT_EXEC=`readlink -f $STACKMGMT_EXEC`
122
123 # Dynamic library:
124 #available=
125 #for DYNLIB in ${DYNLIBS[@]}; do
126 #  echo -n "Looking dynamic library at '$DYNLIB' ... "
127 #  [ -x $DYNLIB ] && { available=yes ; echo "available !" ; break ; }
128 #  echo "not found"
129 #done
130 #[ -z "$available" ] && _exit "Anna Diameter Launcher Dynamic Procedure Library (ADML) is not installed neither linked. See README.md (Install section)."
131
132 [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)."
133
134 echo
135 if [ "$1" = "" ]
136 then
137   echo
138   echo "Deploy one of these versions:"
139   echo
140   echo " (a)dvanced version:     includes burst management script and templates for different scenarios. Automatic configuration during start."
141   echo " (b)asic version:        4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
142   echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs. Requires a server to perform the tests."
143   echo " (s)ystem test client:   special client for stress testing. Requires a server/s to perform the tests."
144   echo
145   echo "Input option [b]:"
146   read option
147   [ "$option" = "" ] && option=b
148 else
149   option=$1
150 fi
151
152 case $option in
153   a)
154     echo "Advanced deployment"
155     DEPLOYMENTS_DIR=deployments/advanced
156     DPATH_dflt=$HOME/ADML-advanced
157   ;;
158
159   b)
160     echo "Basic deployment"
161     DEPLOYMENTS_DIR=deployments/basic
162     DPATH_dflt=$HOME/ADML-basic
163   ;;
164
165   f)
166     echo "FT deployment"
167     DEPLOYMENTS_DIR=deployments/ft-client
168     DPATH_dflt=$HOME/ADML-ft-client
169   ;;
170
171   s)
172     echo "ST deployment"
173     DEPLOYMENTS_DIR=deployments/st-client
174     DPATH_dflt=$HOME/ADML-st-client
175   ;;
176
177   *)
178     _exit "Invalid deployment type '$option' !!"
179   ;;
180 esac
181
182 echo
183 if [ "$2" = "" ]
184 then
185   echo "Input deployment path [$DPATH_dflt]:"
186   read DPATH
187   [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
188 else
189   DPATH=$2
190 fi
191
192 [ -d $DPATH ] && _exit "The installation path '$DPATH' must not exists."
193 EXE=`basename $DPATH`
194
195 echo "Copying to '$DPATH' ..."
196 mkdir -p $DPATH
197 mkdir -p $DPATH/stacks
198 mkdir -p $DPATH/DTDs
199 mkdir -p $DPATH/counters
200 mkdir -p $DPATH/test-reports
201
202 # Dynamic libs:
203 mkdir -p $DPATH/dynlibs
204 cd ../../../dynamic/launcher
205 DYNLIBS=( $(find . -name "*.so") )
206 for dl in ${DYNLIBS[@]}
207 do
208   dir=$(dirname $dl | xargs dirname)
209   mkdir -p $DPATH/dynlibs/$dir
210   cp $dir/$dynlib_variant/*.so $DPATH/dynlibs/$dir
211   cp $dir/*.xml $DPATH/dynlibs/$dir 2>/dev/null
212   cp $dir/dynamic.suffix $DPATH/dynlibs/$dir 2>/dev/null
213 done
214 cd - >/dev/null
215 cp ./resources/scripts/select_dynlib.sh $DPATH/dynlibs/select.sh
216 cd $DPATH/dynlibs
217 ln -s default/libanna_dynamicLauncherProcedure.so
218 cd - >/dev/null
219
220 [ "$option" = "b" ] && mkdir -p $DPATH/services
221
222 # ADML executable:
223 if [ "$EXEC" = "$EXEC_installed" ]
224 then
225   ln -s $EXEC_installed $DPATH/ADML-launcher
226 else
227   cp $EXEC $DPATH/ADML-launcher
228 fi
229
230 # Stack management tool:
231 if [ "$STACKMGMT_EXEC" = "$STACKMGMT_EXEC_installed" ]
232 then
233   ln -s $STACKMGMT_EXEC_installed $DPATH/stacks/stack-mgmt
234 fi
235 # Copy binary just in case: 
236 [ ! -f $DPATH/stacks/stack-mgmt ] && cp $STACKMGMT_EXEC $DPATH/stacks/stack-mgmt
237
238 cp -rL $DEPLOYMENTS_DIR/* $DPATH
239 cp $SETUPS_DIR/*xml $DPATH/stacks
240 cp $SETUPS_DIR/*sh $DPATH/stacks
241 cp $SETUPS_DIR/readme.txt $DPATH/stacks
242 mkdir $DPATH/stacks/other_examples
243 cp $STACK_EXAMPLES/* $DPATH/stacks/other_examples 
244 cp $MSGDTD $DPATH/DTDs
245 cp $DCTDTD $DPATH/DTDs
246 cp $SRVDTD $DPATH/DTDs
247 [ "$option" = "b" ] && cp $SERVICES/* $DPATH/services
248
249 echo "Preparing ..."
250 cd $DPATH
251 createRunScript $option
252 stacks/makeAutonomous.sh commands_qosControl.xml stacks/stack-mgmt >/dev/null
253 ln -s stacks/autonomous.commands_qosControl.xml dictionary.xml
254 cd - >/dev/null
255
256 if [ "$option" = "s" ]
257 then
258   cd $DPATH
259   ln -s services_example services
260   mv run.sh .run-one.sh
261   mv run_all.sh run.sh
262   mv operation.sh .operation-one.sh
263   mv operation_all.sh operation.sh
264   rm dictionary.xml
265   cd - >/dev/null
266 fi
267
268 # Help:
269 echo
270 echo "Go to '$DPATH' and see README file"
271 echo
272 echo "Done!"
273 echo
274 echo
275
276