76ccd8bd2a242883e2ceb9c7ed44e6f3ec11f0da
[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
12 #############
13 # FUNCTIONS #
14 #############
15 _exit () {
16    echo
17    echo $1
18    echo
19    exit
20 }
21
22 # $1: deployment type
23 createRunScript () {
24
25   # Basic launcher 'run.sh' will be created at deployment configuration: 
26   [ "$1" = "b" ] && return
27   [ "$1" = "a" ] && exe=ADL-launcher
28   [ "$1" = "f" ] && { exe=ADL-ftclient ; ln -s ADL-launcher $exe ; }
29
30   cat << EOF > run.sh
31 #!/bin/bash
32 cd \`dirname \$0\`
33 EXE=$exe
34 STARTED=\`pgrep \$EXE 2>/dev/null\`
35 [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
36 ./pre-start.sh
37 0> launcher.traces
38 rm -f counters/*
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 "Basic checkings ..."
81 [ ! -f $EXEC ] && _exit "Anna Diameter Launcher (ADL) is not linked. Execute 'scons' for 'anna' suite."
82 [ ! -d $SETUPS_DIR ] && _exit "Diameter stacks not found ($SETUPS_DIR)."
83
84 echo
85 echo "Deploy one of these versions:"
86 echo
87 echo " (a)dvanced version:     includes burst management script and templates for different scenarios. Automatic configuration during start."
88 echo " (b)asic version:        4 types of launcher (client, server, balancer, dummy), lightly configured and managed through SIGURS2 method."
89 echo " (f)unction test client: special client with regexp scheduler script based on splitted traffic logs."
90 echo
91 echo "Input option [b]:"
92 read option
93 [ "$option" = "" ] && option=b
94 case $option in
95   a)
96     DEPLOYMENTS_DIR=deployments/advanced
97     DPATH_dflt=$HOME/ADL-advanced
98   ;;
99
100   b)
101     DEPLOYMENTS_DIR=deployments/basic
102     DPATH_dflt=$HOME/ADL-basic
103   ;;
104
105   f)
106     DEPLOYMENTS_DIR=deployments/ft-client
107     DPATH_dflt=$HOME/ADL-ft-client
108   ;;
109
110   *)
111     _exit "Unknown option !!"
112   ;;
113 esac
114
115 echo
116 echo "Input deployment path [$DPATH_dflt]:"
117 read DPATH
118 [ "$DPATH" = "" ] && DPATH=$DPATH_dflt
119 [ -d $DPATH ] && _exit "The path '$DPATH' already exists. Remove it before continue..."
120
121 echo "Copying ..."
122 mkdir -p $DPATH
123 mkdir -p $DPATH/stacks
124 mkdir -p $DPATH/DTDs
125 mkdir -p $DPATH/counters
126 mkdir -p $DPATH/resources
127 cp $EXEC $DPATH/ADL-launcher
128 cp -rL $DEPLOYMENTS_DIR/* $DPATH
129 cp resources/* $DPATH/resources
130 cp $SETUPS_DIR/*xml $DPATH/stacks
131 cp $SETUPS_DIR/*sh $DPATH/stacks
132 cp $SETUPS_DIR/readme.txt $DPATH/stacks
133 cp $MSGDTD $DPATH/DTDs
134 cp $DCTDTD $DPATH/DTDs
135
136 echo "Preparing ..."
137 cd $DPATH
138 createRunScript $option
139 createDictionaryPaths
140 cd - >/dev/null
141
142 # Help:
143 echo
144 echo "Go to '$DPATH' and see README file"
145 echo
146 echo "Done!"
147 echo
148 echo
149
150