906a0b2de2bfcc684af66da913b156998a0c36f8
[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
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 # Dictionary creation:
108 available=
109 for STACKMGMT_EXEC in ${STACKMGMT_EXECS[@]}; do
110   echo -n "Looking stack management executable at '$STACKMGMT_EXEC' ... "
111   [ -x $STACKMGMT_EXEC ] && { available=yes ; echo "available !" ; break ; }
112   echo "not found"
113 done
114 [ -z "$available" ] && _exit "Anna Diameter Stack Management Tool is not installed neither linked. See README.md (Install section)."
115 STACKMGMT_EXEC=`readlink -f $STACKMGMT_EXEC`
116
117 # Dynamic library:
118 available=
119 for DYNLIB in ${DYNLIBS[@]}; do
120   echo -n "Looking dynamic library at '$DYNLIB' ... "
121   [ -x $DYNLIB ] && { available=yes ; echo "available !" ; break ; }
122   echo "not found"
123 done
124 [ -z "$available" ] && _exit "Anna Diameter Launcher Dynamic Procedure Library (ADML) is not installed neither linked. See README.md (Install section)."
125
126 [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)."
127
128 echo
129 if [ "$1" = "" ]
130 then
131   echo
132   echo "Deploy one of these versions:"
133   echo
134   echo " (a)dvanced version:     includes burst management script and templates for different scenarios. Automatic configuration during start."
135   echo " (b)asic version:        4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
136   echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs. Requires a server to perform the tests."
137   echo " (s)ystem test client:   special client for stress testing. Requires a server/s to perform the tests."
138   echo
139   echo "Input option [b]:"
140   read option
141   [ "$option" = "" ] && option=b
142 else
143   option=$1
144 fi
145
146 case $option in
147   a)
148     echo "Advanced deployment"
149     DEPLOYMENTS_DIR=deployments/advanced
150     DPATH_dflt=$HOME/ADML-advanced
151   ;;
152
153   b)
154     echo "Basic deployment"
155     DEPLOYMENTS_DIR=deployments/basic
156     DPATH_dflt=$HOME/ADML-basic
157   ;;
158
159   f)
160     echo "FT deployment"
161     DEPLOYMENTS_DIR=deployments/ft-client
162     DPATH_dflt=$HOME/ADML-ft-client
163   ;;
164
165   s)
166     echo "ST deployment"
167     DEPLOYMENTS_DIR=deployments/st-client
168     DPATH_dflt=$HOME/ADML-st-client
169   ;;
170
171   *)
172     _exit "Invalid deployment type '$option' !!"
173   ;;
174 esac
175
176 echo
177 if [ "$2" = "" ]
178 then
179   echo "Input deployment path [$DPATH_dflt]:"
180   read DPATH
181   [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
182 else
183   DPATH=$2
184 fi
185
186 [ -d $DPATH ] && _exit "The installation path '$DPATH' must not exists."
187 EXE=`basename $DPATH`
188
189 echo "Copying to '$DPATH' ..."
190 mkdir -p $DPATH
191 mkdir -p $DPATH/stacks
192 mkdir -p $DPATH/DTDs
193 mkdir -p $DPATH/counters
194 mkdir -p $DPATH/test-reports
195 cp $DYNLIB $DPATH
196
197 [ "$option" = "b" ] && mkdir -p $DPATH/services
198
199 # ADML executable:
200 if [ "$EXEC" = "$EXEC_installed" ]
201 then
202   ln -s $EXEC_installed $DPATH/ADML-launcher
203 else
204   cp $EXEC $DPATH/ADML-launcher
205 fi
206
207 # Stack management tool:
208 if [ "$STACKMGMT_EXEC" = "$STACKMGMT_EXEC_installed" ]
209 then
210   ln -s $STACKMGMT_EXEC_installed $DPATH/stacks/stack-mgmt
211 fi
212 # Copy binary just in case: 
213 [ ! -f $DPATH/stacks/stack-mgmt ] && cp $STACKMGMT_EXEC $DPATH/stacks/stack-mgmt
214
215 cp -rL $DEPLOYMENTS_DIR/* $DPATH
216 cp $SETUPS_DIR/*xml $DPATH/stacks
217 cp $SETUPS_DIR/*sh $DPATH/stacks
218 cp $SETUPS_DIR/readme.txt $DPATH/stacks
219 mkdir $DPATH/stacks/other_examples
220 cp $STACK_EXAMPLES/* $DPATH/stacks/other_examples 
221 cp $MSGDTD $DPATH/DTDs
222 cp $DCTDTD $DPATH/DTDs
223 cp $SRVDTD $DPATH/DTDs
224 [ "$option" = "b" ] && cp $SERVICES/* $DPATH/services
225
226 echo "Preparing ..."
227 cd $DPATH
228 createRunScript $option
229 stacks/makeAutonomous.sh commands_qosControl.xml stacks/stack-mgmt >/dev/null
230 ln -s stacks/autonomous.commands_qosControl.xml dictionary.xml
231 cd - >/dev/null
232
233 # Help:
234 echo
235 echo "Go to '$DPATH' and see README file"
236 echo
237 echo "Done!"
238 echo
239 echo
240
241