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