Make absolute
[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 STACK_EXAMPLES=$SCR_DIR/resources/stack_examples
13 SRVDTD=$SERVICES/services.dtd
14 VARIANT=
15
16 #############
17 # FUNCTIONS #
18 #############
19 _exit () {
20    echo -e "\n$1\n"
21    exit 1
22 }
23
24 usage () {
25   echo "Usage: $0 [deployment_type: a|b|f|s] [deployment_path]"
26   echo
27   echo "       deployment_type:"
28   echo "          a=advanced"
29   echo "          b=basic"
30   echo "          f=function test client"
31   echo "          s=system test client"
32   echo "       deployment_path:"
33   echo "          non-existent path directory."
34   echo
35   echo "       For example:"
36   echo "          $0 b $HOME/ADML-basicServer"
37   echo "          $0 b $HOME/ADML-MMSbalancer"
38   echo "          $0 f $HOME/ADML-tester"
39   echo "          $0 s $HOME/ADML-stress-client"
40   echo
41   exit 0
42 }
43  
44 # $1: deployment type
45 createRunScript () {
46   # Basic launcher 'run.sh' will be created at deployment configuration: 
47   [ "$1" = "b" ] && return
48
49   local other=
50   [ "$1" = "a" ] && other="--httpServer \`grep -v ^# .httpServer\`"
51   [ "$1" = "f" ] && ln -s ADML-launcher $EXE
52   [ "$1" = "s" ] && { other="--disableLogs"; ln -s ADML-launcher $EXE ; }
53
54   echo "Creating 'run.sh' script ..."
55
56   cat << EOF > run.sh
57 #!/bin/bash
58 cd \`dirname \$0\`
59 EXE=$EXE
60 STARTED=\`pgrep \$EXE$ 2>/dev/null\`
61 [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
62 ./pre-start.sh
63 0> launcher.trace
64 rm -f counters/* test-reports/*
65 # Execution line:
66 export LD_LIBRARY_PATH=\$PWD/dynlibs
67 ./\$EXE --services services.xml --cntDir counters --tmDir test-reports $other &
68 echo \$! > .pid
69 EOF
70
71   chmod a+x run.sh
72 }
73
74 #############
75 # EXECUTION #
76 #############
77 cd $SCR_DIR
78 echo
79 echo "---------------------------------------"
80 echo "Anna Diameter Launcher (ADML) deployment"
81 echo "---------------------------------------"
82 [ "$1" = "--help" -o "$1" = "-h" ] && usage
83 echo " (--help or -h for more info)"
84 echo
85 echo "Basic checkings ..."
86
87 # Get variant and main executables:
88 [ -f $SCR_DIR/release/example_diameter_launcher ] && VARIANT=release
89 [ -f $SCR_DIR/debug/example_diameter_launcher ] && VARIANT=debug
90 [ -z "$VARIANT" ] && _exit "Cannot locate neither 'release' nor 'debug' variant !"
91 echo "Variant: $VARIANT"
92 ADML_EXEC=$SCR_DIR/$VARIANT/example_diameter_launcher
93 STACKMGMT_EXEC=$(readlink -f $SCR_DIR/../stackManagement/$VARIANT/example_diameter_stackManagement)
94
95 [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)."
96
97 echo
98 if [ "$1" = "" ]
99 then
100   echo
101   echo "Deploy one of these versions:"
102   echo
103   echo " (a)dvanced version:     includes burst management script and templates for different scenarios. Automatic configuration during start."
104   echo " (b)asic version:        4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
105   echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs. Requires a server to perform the tests."
106   echo " (s)ystem test client:   special client for stress testing. Requires a server/s to perform the tests."
107   echo
108   echo "Input option [b]:"
109   read option
110   [ "$option" = "" ] && option=b
111 else
112   option=$1
113 fi
114
115 case $option in
116   a)
117     echo "Advanced deployment"
118     DEPLOYMENTS_DIR=deployments/advanced
119     DPATH_dflt=$HOME/ADML-advanced
120   ;;
121
122   b)
123     echo "Basic deployment"
124     DEPLOYMENTS_DIR=deployments/basic
125     DPATH_dflt=$HOME/ADML-basic
126   ;;
127
128   f)
129     echo "FT deployment"
130     DEPLOYMENTS_DIR=deployments/ft-client
131     DPATH_dflt=$HOME/ADML-ft-client
132   ;;
133
134   s)
135     echo "ST deployment"
136     DEPLOYMENTS_DIR=deployments/st-client
137     DPATH_dflt=$HOME/ADML-st-client
138   ;;
139
140   *)
141     _exit "Invalid deployment type '$option' !!"
142   ;;
143 esac
144
145 echo
146 if [ "$2" = "" ]
147 then
148   echo "Input deployment path [$DPATH_dflt]:"
149   read DPATH
150   [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
151 else
152   DPATH=$2
153 fi
154
155 [ -d $DPATH ] && _exit "The installation path '$DPATH' must not exists."
156 EXE=`basename $DPATH`
157
158 echo "Copying to '$DPATH' ..."
159 mkdir -p $DPATH
160 mkdir -p $DPATH/stacks
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 executables:
204 cp $ADML_EXEC $DPATH/ADML-launcher
205 [ ! -f $DPATH/stacks/stack-mgmt ] && cp $STACKMGMT_EXEC $DPATH/stacks/stack-mgmt
206
207 # Copy resources:
208 cp -rL $DEPLOYMENTS_DIR/* $DPATH
209 cp $SETUPS_DIR/*xml $DPATH/stacks
210 cp $SETUPS_DIR/*sh $DPATH/stacks
211 cp $SETUPS_DIR/readme.txt $DPATH/stacks
212 mkdir $DPATH/stacks/other_examples
213 cp $STACK_EXAMPLES/* $DPATH/stacks/other_examples 
214 cp $MSGDTD $DPATH/DTDs
215 cp $DCTDTD $DPATH/DTDs
216 cp $SRVDTD $DPATH/DTDs
217 [ "$option" = "b" ] && cp $SERVICES/* $DPATH/services
218
219 echo "Preparing ..."
220 cd $DPATH
221 createRunScript $option
222 stacks/makeAutonomous.sh commands_qosControl.xml stacks/stack-mgmt >/dev/null
223 ln -s stacks/autonomous.commands_qosControl.xml dictionary.xml
224 cd - >/dev/null
225
226 if [ "$option" = "s" ]
227 then
228   cd $DPATH
229   ln -s services_example services
230   mv run.sh .run-one.sh
231   mv run_all.sh run.sh
232   mv operation.sh .operation-one.sh
233   mv operation_all.sh operation.sh
234   rm dictionary.xml
235   cd - >/dev/null
236 fi
237
238 # Help:
239 echo "Done !"
240 echo "(see README at '$DPATH')"
241 echo
242