f83ec69f817d0761e406370f3d9621070ed2a64e
[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 BASE_PROT=commands_baseProtocol.xml
10 SERVICES=./resources/services_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 #############
22 # FUNCTIONS #
23 #############
24 _exit () {
25    echo
26    echo $1
27    echo
28    exit 1
29 }
30
31 usage () {
32   echo "Usage: $0 [deployment_type: a|b|f] [deployment_path]"
33   echo
34   echo "       deployment_type:"
35   echo "          a=advanced"
36   echo "          b=basic"
37   echo "          f=function test client"
38   echo "       deployment_path:"
39   echo "          non-existent path directory."
40   echo
41   echo "       For example:"
42   echo "          $0 b $HOME/ADML/basicServer"
43   echo "          $0 b $HOME/ADML/MMSbalancer"
44   echo "          $0 f $HOME/ADML/tester"
45   echo
46   exit 0
47 }
48  
49 # $1: deployment type
50 createRunScript () {
51   # Basic launcher 'run.sh' will be created at deployment configuration: 
52   [ "$1" = "b" ] && return
53
54   local other=
55   [ "$1" = "a" ] && { exe=ADML-launcher ; other="--httpServer \`grep -v ^# .httpServer\`"; }
56   [ "$1" = "f" ] && { exe=ADML-ftclient ; ln -s ADML-launcher $exe ; }
57
58   echo "Creating 'run.sh' script ..."
59
60   cat << EOF > run.sh
61 #!/bin/bash
62 cd \`dirname \$0\`
63 EXE=$exe
64 STARTED=\`pgrep \$EXE 2>/dev/null\`
65 [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
66 ./pre-start.sh
67 0> launcher.trace
68 rm -f counters/*
69 # Execution line:
70 ./\$EXE --services services.xml --cntDir counters $other &
71 echo \$! > .pid
72 EOF
73
74   chmod a+x run.sh
75 }
76
77 createDictionaryPaths () {
78   echo "Creating dictionaries ..."
79
80   for i in stacks/*commands*xml
81   do
82     stacks/dependence.sh $i >/dev/null
83     stack=`basename $i`
84     if test "$stack" != "$BASE_PROT"
85     then
86       > .dictionary-${stack}
87       for j in `cat ${i}.dep`
88       do
89         echo -n "${j} " >> .dictionary-${stack}
90       done
91       echo "stacks/$BASE_PROT stacks/${stack}" >> .dictionary-${stack}
92     fi
93   done
94
95   # Create autonomous dictionaries:
96   mkdir stacks/autonomous
97   for i in `ls .dictionary-*`
98   do
99     name=$(echo $i | cut -d\- -f2)
100     $STACKMGMT_EXEC `cat $i` >/dev/null
101     mv result.xml stacks/autonomous/$name
102   done
103
104   # Cleanup:
105   rm -f stacks/*.dep
106   rm -f .dictionary-*
107   rm -f example_diameter_stackManagement.trace*
108
109   # Default:
110   ln -s stacks/autonomous/commands_qosControl.xml dictionary.xml
111 }
112
113 #############
114 # EXECUTION #
115 #############
116 cd `dirname $0`
117 echo
118 echo "---------------------------------------"
119 echo "Anna Diameter Launcher (ADML) deployment"
120 echo "---------------------------------------"
121 [ "$1" = "--help" -o "$1" = "-h" ] && usage
122 echo " (--help or -h for more info)"
123 echo
124 echo "Basic checkings ..."
125 # Launcher executable:
126 available=
127 for EXEC in ${EXECS[@]}; do
128   echo -n "Looking executable at '$EXEC' ... "
129   [ -x $EXEC ] && { available=yes ; echo "available !" ; break ; }
130   echo "not found"
131 done
132 [ -z "$available" ] && _exit "Anna Diameter Launcher (ADML) is not installed neither linked. See README.md (Install section)."
133 # Dictionary creation:
134 available=
135 for STACKMGMT_EXEC in ${STACKMGMT_EXECS[@]}; do
136   echo -n "Looking stack management executable at '$STACKMGMT_EXEC' ... "
137   [ -x $STACKMGMT_EXEC ] && { available=yes ; echo "available !" ; break ; }
138   echo "not found"
139 done
140 [ -z "$available" ] && _exit "Anna Diameter Stack Management Tool is not installed neither linked. See README.md (Install section)."
141
142 [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)."
143
144 echo
145 if [ "$1" = "" ]
146 then
147   echo
148   echo "Deploy one of these versions:"
149   echo
150   echo " (a)dvanced version:     includes burst management script and templates for different scenarios. Automatic configuration during start."
151   echo " (b)asic version:        4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
152   echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs. Requires a server to perform the tests."
153   echo
154   echo "Input option [b]:"
155   read option
156   [ "$option" = "" ] && option=b
157 else
158   option=$1
159 fi
160
161 case $option in
162   a)
163     echo "Advanced deployment"
164     DEPLOYMENTS_DIR=deployments/advanced
165     DPATH_dflt=$HOME/ADML/advanced
166   ;;
167
168   b)
169     echo "Basic deployment"
170     DEPLOYMENTS_DIR=deployments/basic
171     DPATH_dflt=$HOME/ADML/basic
172   ;;
173
174   f)
175     echo "FT deployment"
176     DEPLOYMENTS_DIR=deployments/ft-client
177     DPATH_dflt=$HOME/ADML/ft-client
178   ;;
179
180   *)
181     _exit "Invalid deployment type '$option' !!"
182   ;;
183 esac
184
185 echo
186 if [ "$2" = "" ]
187 then
188   echo "Input deployment path [$DPATH_dflt]:"
189   read DPATH
190   [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
191 else
192   DPATH=$2
193 fi
194
195 [ -d $DPATH ] && _exit "The installation path '$DPATH' must not exists."
196
197 echo "Copying to '$DPATH' ..."
198 mkdir -p $DPATH
199 mkdir -p $DPATH/stacks
200 mkdir -p $DPATH/DTDs
201 mkdir -p $DPATH/counters
202 [ "$option" = "b" ] && mkdir -p $DPATH/services
203 if [ "$EXEC" = "$EXEC_installed" ]
204 then
205   ln -s $EXEC_installed $DPATH/ADML-launcher
206 else
207   cp $EXEC $DPATH/ADML-launcher
208 fi
209 cp -rL $DEPLOYMENTS_DIR/* $DPATH
210 cp $SETUPS_DIR/*xml $DPATH/stacks
211 cp $SETUPS_DIR/*sh $DPATH/stacks
212 cp $SETUPS_DIR/readme.txt $DPATH/stacks
213 cp $MSGDTD $DPATH/DTDs
214 cp $DCTDTD $DPATH/DTDs
215 cp $SRVDTD $DPATH/DTDs
216 [ "$option" = "b" ] && cp $SERVICES/* $DPATH/services
217
218 echo "Preparing ..."
219 cd $DPATH
220 createRunScript $option
221 createDictionaryPaths
222 cd - >/dev/null
223
224 # Help:
225 echo
226 echo "Go to '$DPATH' and see README file"
227 echo
228 echo "Done!"
229 echo
230 echo
231
232