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