Fixes
[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 [ -d $PROJECT_ROOT/build/Release ] && VARIANT=Release
90 [ -d $PROJECT_ROOT/build/Debug ] && VARIANT=Debug
91 [ -z "$VARIANT" ] && _exit "Cannot locate neither 'Release' nor 'Debug' variant !"
92 echo "Variant: $VARIANT"
93 BIN_DIR=$PROJECT_ROOT/build/$VARIANT/bin
94 LIB_DIR=$PROJECT_ROOT/build/$VARIANT/lib
95
96 # Main executables:
97 ADML_EXEC=$BIN_DIR/diameter_launcher
98 STACKMGMT_EXEC=$BIN_DIR/diameter_stackManagement
99
100 [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)."
101
102 echo
103 if [ "$1" = "" ]
104 then
105   echo
106   echo "Deploy one of these versions:"
107   echo
108   echo " (a)dvanced version:     includes burst management script and templates for different scenarios. Automatic configuration during start."
109   echo " (b)asic version:        4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
110   echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs. Requires a server to perform the tests."
111   echo " (s)ystem test client:   special client for stress testing. Requires a server/s to perform the tests."
112   echo
113   echo "Input option [b]:"
114   read option
115   [ "$option" = "" ] && option=b
116 else
117   option=$1
118 fi
119
120 case $option in
121   a)
122     echo "Advanced deployment"
123     DEPLOYMENTS_DIR=deployments/advanced
124     DPATH_dflt=$HOME/ADML-advanced
125   ;;
126
127   b)
128     echo "Basic deployment"
129     DEPLOYMENTS_DIR=deployments/basic
130     DPATH_dflt=$HOME/ADML-basic
131   ;;
132
133   f)
134     echo "FT deployment"
135     DEPLOYMENTS_DIR=deployments/ft-client
136     DPATH_dflt=$HOME/ADML-ft-client
137   ;;
138
139   s)
140     echo "ST deployment"
141     DEPLOYMENTS_DIR=deployments/st-client
142     DPATH_dflt=$HOME/ADML-st-client
143   ;;
144
145   *)
146     _exit "Invalid deployment type '$option' !!"
147   ;;
148 esac
149
150 echo
151 if [ "$2" = "" ]
152 then
153   echo "Input deployment path [$DPATH_dflt]:"
154   read DPATH
155   [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
156 else
157   DPATH=$2
158 fi
159
160 [ -d $DPATH ] && _exit "The installation path '$DPATH' must not exists."
161 EXE=`basename $DPATH`
162
163 echo "Copying to '$DPATH' ..."
164 mkdir -p $DPATH
165 mkdir -p $DPATH/DTDs
166 mkdir -p $DPATH/counters
167 mkdir -p $DPATH/test-reports
168
169 # Dynamic libs:
170 cp -r $LIB_DIR/dynamic/launcher $DPATH/dynlibs
171
172 # Get stuff from leaf directories:
173 cd $LIB_DIR/dynamic/launcher
174 leafs=( $(find . -type d -links 2) )
175 cd - >/dev/null
176
177 cd $PROJECT_ROOT/dynamic/launcher
178 for dir in ${leafs[@]}
179 do
180     cp $dir/*.xml $DPATH/dynlibs/$dir 2>/dev/null
181     cp $dir/dynamic.suffix $DPATH/dynlibs/$dir 2>/dev/null
182     cp -r $dir/services $DPATH/dynlibs/$dir 2>/dev/null
183 done
184 cd - >/dev/null
185
186 # ADML dynamic libs selection script:
187 cp $SCR_DIR/resources/scripts/select_dynlib.sh $DPATH/dynlibs/select.sh
188
189 # Default dynamic library:
190 cd $DPATH/dynlibs
191 ln -s default/liblauncher_procedure_default_shared.so
192 cd - >/dev/null
193
194 # Basic setup:
195 [ "$option" = "b" ] && mkdir -p $DPATH/services
196
197 # Copy resources:
198 cp -rL $DEPLOYMENTS_DIR/* $DPATH
199 mkdir -p $DPATH/stack_examples/other
200 cp $STACK_EXAMPLES/* $DPATH/stack_examples/other
201 cp $SETUPS_DIR/*xml $DPATH/stack_examples
202 cp $SETUPS_DIR/*sh $DPATH/stack_examples
203 cp $SETUPS_DIR/readme.txt $DPATH/stack_examples
204 cp $MSGDTD $DPATH/DTDs
205 cp $DCTDTD $DPATH/DTDs
206 cp $SRVDTD $DPATH/DTDs
207 [ "$option" = "b" ] && cp $SERVICES/* $DPATH/services
208 cp $SCRIPTS/clone.sh $DPATH
209 cp $SCRIPTS/tinyTestcase.sh $DPATH
210
211 # Copy executables:
212 cp $ADML_EXEC $DPATH/ADML
213 [ ! -f $DPATH/stack_examples/stack-mgmt ] && cp $STACKMGMT_EXEC $DPATH/stack_examples/stack-mgmt
214
215 echo "Default stack dynamic generation ..."
216 cd $DPATH
217 createRunScript $option
218 stack_examples/makeAutonomous.sh commands_qosControl.xml stack_examples/stack-mgmt >/dev/null
219 ln -s stack_examples/autonomous.commands_qosControl.xml dictionary.xml
220 cd - >/dev/null
221
222 if [ "$option" = "s" ]
223 then
224   cd $DPATH
225   ln -s services_example services
226   mv run.sh .run-one.sh
227   mv run_all.sh run.sh
228   mv operation.sh .operation-one.sh
229   mv operation_all.sh operation.sh
230   rm dictionary.xml
231   cd - >/dev/null
232 fi
233
234 # Help:
235 echo "Done !"
236 echo "(see README at '$DPATH')"
237 echo
238