Launcher resources refactoring. New type included: FT testing client.
[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 EXEC=./debug/example_diameter_launcher
11 DPATH_dflt=$HOME/ADL
12
13 #############
14 # FUNCTIONS #
15 #############
16 _exit () {
17    echo
18    echo $1
19    echo
20    exit
21 }
22
23 # $1: deployment type
24 createRunScript () {
25
26   # Basic launcher 'run.sh' will be created at deployment configuration: 
27   [ "$1" = "b" ] && return
28   [ "$1" = "a" ] && exe=ADL-launcher
29   [ "$1" = "f" ] && { exe=ADL-ftclient ; ln -s ADL-launcher $exe ; }
30
31   cat << EOF > run.sh
32 #!/bin/bash
33 cd \`dirname \$0\`
34 EXE=$exe
35 STARTED=\`pgrep \$EXE 2>/dev/null\`
36 [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
37 ./pre-start.sh
38 0> launcher.traces
39 # Execution line:
40 ./\$EXE -cntDir counters $(for i in `cat args.txt | grep -v "^#"`; do echo -n "$i "; done)&
41 echo \$! > .pid
42 EOF
43
44   chmod a+x run.sh
45   rm args.txt
46 }
47
48 createDictionaryPaths () {
49   for i in stacks/*commands*xml
50   do
51     stacks/dependence.sh $i >/dev/null
52     stack=`basename $i`
53     if test "$stack" != "$BASE_PROT"
54     then
55       > .dictionary__${stack}
56       for j in `cat ${i}.dep`
57       do
58         echo -n "${j}," >> .dictionary__${stack}
59       done
60       echo "stacks/$BASE_PROT,stacks/${stack}" >> .dictionary__${stack}
61     fi
62   done
63
64   # Default:
65   ln -s .dictionary__commands_qosControl.xml .dictionary
66
67   # Remove deps:
68   rm -f stacks/*.dep
69 }
70
71 #############
72 # EXECUTION #
73 #############
74 cd `dirname $0`
75 echo
76 echo "---------------------------------------"
77 echo "Anna Diameter Launcher (ADL) deployment"
78 echo "---------------------------------------"
79 echo
80 echo "Input deployment path [$DPATH_dflt]:"
81 read DPATH
82 [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
83 [ -d $DPATH ] && _exit "The path '$DPATH' already exists. Remove it before continue..."
84
85 echo "Basic checkings ..."
86 [ ! -f $EXEC ] && _exit "Anna Diameter Launcher (ADL) is not linked. Execute 'scons' for 'anna' suite."
87 [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR). Perhaps you executed this script out of its parent path."
88
89 echo
90 echo "Deploy one of these versions:"
91 echo
92 echo " (a)dvanced version:     includes burst management script and templates for different scenarios. Automatic configuration during start."
93 echo " (b)asic version:        4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
94 echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs."
95 echo
96 echo "Input option [b]:"
97 read option
98 [ "$option" = "" ] && option=b
99 case $option in
100   a)
101     RESOURCES_DIR=resources/advanced
102   ;;
103
104   b)
105     RESOURCES_DIR=resources/basic
106   ;;
107
108   f)
109     RESOURCES_DIR=resources/ft-client
110   ;;
111
112   *)
113     _exit "Unknown option !!"
114   ;;
115 esac
116
117 echo "Copying ..."
118 mkdir -p $DPATH
119 mkdir -p $DPATH/stacks
120 mkdir -p $DPATH/DTDs
121 mkdir -p $DPATH/counters
122 cp $EXEC $DPATH/ADL-launcher
123 cp -rL $RESOURCES_DIR/* $DPATH
124 cp $SETUPS_DIR/*xml $DPATH/stacks
125 cp $SETUPS_DIR/*sh $DPATH/stacks
126 cp $SETUPS_DIR/readme.txt $DPATH/stacks
127 cp $MSGDTD $DPATH/DTDs
128 cp $DCTDTD $DPATH/DTDs
129
130 echo "Preparing ..."
131 cd $DPATH
132 createRunScript $option
133 createDictionaryPaths
134 cd - >/dev/null
135
136 # Help:
137 echo
138 echo "Go to '$DPATH' and see README file"
139 echo
140 echo "Done!"
141 echo
142 echo
143
144