Improve deployments and installation procedures
[anna.git] / example / diameter / launcher / deployments / basic / configure.sh
1 #!/bin/bash
2
3 #############
4 # VARIABLES #
5 #############
6
7 # Diameter dictionary:
8 STD_DICTIONARY=stacks/avps_etsi.xml,stacks/avps_ietf.xml,stacks/avps_tgpp.xml,stacks/commands_baseProtocol.xml
9 APP_DICTIONARY=stacks/commands_qosControl.xml
10 DICTIONARY=$STD_DICTIONARY,$APP_DICTIONARY
11
12 # Communication endpoints:
13 LOCAL_STANDARD_ENDPOINT=localhost:3868
14 EXAMPLE_ENTITY_4_BALANCER=192.168.12.11:3868,192.168.12.21:3868
15 CONNS=10
16
17 # General
18 EXE_BN=ADL-launcher
19
20 #############
21 # FUNCTIONS #
22 #############
23
24 _exit () {
25   echo
26   echo $1
27   echo
28   exit 1
29 }
30
31 # $1: process name
32 createRunScript () {
33
34   cat << EOF > run.sh
35 #!/bin/bash
36 cd \`dirname \$0\`
37 STARTED=\`pgrep $1 2>/dev/null\`
38 [ \$? -eq 0 ] && { echo "Already started!"; echo "\$STARTED" ; exit 1 ; }
39 0> launcher.traces
40 rm -f counters/*
41 # Execution line:
42 ./$@ &
43 echo \$! > .pid
44 EOF
45
46   chmod a+x run.sh
47 }
48
49 # $1: input option (c, s, b, d)
50 # Retuns the type of launcher logical name for the input option
51 get_tol () {
52   [ "$1" = "c" ] && echo client
53   [ "$1" = "s" ] && echo server
54   [ "$1" = "b" ] && echo balancer
55   [ "$1" = "d" ] && echo dummy
56 }
57
58 #############
59 # EXECUTION #
60 #############
61 cd `dirname $0`
62 SCR_DIR=`pwd`
63 echo
64 echo
65 echo "Configure a (c)lient, (s)erver, (b)alancer or (d)ummy [c]:"
66 read option
67 [ "$option" = "" ] && option=c
68 tol=$(get_tol $option)
69 [ "$tol" = "" ] && _exit "Option '$option' not implemented !!"
70
71 # Tracing
72 TRACING="-cntDir counters"
73 echo
74 echo "Enable debug traces ? (y/n) [n]:"
75 read enable
76 [ "$enable" = "" ] && enable=n
77 [ "$enable" = "y" ] && TRACING="$TRACING -trace debug"
78
79 # Kindness
80 KINDNESS=
81 echo
82 echo "Strict xml for decoded messages ? (y/n) [y]:"
83 echo " (ignoring flags turns a made-up xml representation; execute './$EXE_BN | grep -A1 ignoreFlags:' for more help)"
84 read strict
85 [ "$strict" = "" ] && strict=y
86 [ "$strict" = "n" ] && KINDNESS="-ignoreFlags"
87 if [ "$option" = "s" ]
88 then
89   echo
90   echo "Ignore errors ? (y/n) [n]:"
91   echo " (ignoring errors, the process won't answer Failed-AVP automatically; execute './$EXE_BN | grep -A1 ignoreErrors:' for more help)"
92   read i_errors
93   [ "$i_errors" = "" ] && i_errors=n
94   [ "$i_errors" = "y" ] && KINDNESS="$KINDNESS -ignoreErrors"
95 fi
96
97 # Run script:
98 EXE_LINK=ADL-$tol
99 ln -sf $EXE_BN $EXE_LINK
100
101 case $tol in
102
103   client)
104     ENTITY=$LOCAL_STANDARD_ENDPOINT
105     createRunScript $EXE_LINK -dictionary $DICTIONARY -entity $ENTITY -entityServerSessions $CONNS -diameterServerSessions 0 $KINDNESS $TRACING &
106     ;;
107
108   server)
109     SERVER=$LOCAL_STANDARD_ENDPOINT
110     createRunScript $EXE_LINK -dictionary $DICTIONARY -diameterServer $SERVER -diameterServerSessions $CONNS -entityServerSessions 0 $KINDNESS $TRACING &
111     ;;
112
113   balancer)
114     SERVER=$LOCAL_STANDARD_ENDPOINT
115     ENTITY=$EXAMPLE_ENTITY_4_BALANCER
116     createRunScript $EXE_LINK -dictionary $DICTIONARY -entity $ENTITY -entityServerSessions $CONNS -diameterServer $SERVER -diameterServerSessions $CONNS -balance $KINDNESS $TRACING &
117     ;;
118
119   dummy)
120     createRunScript $EXE_LINK -dictionary $DICTIONARY -entityServerSessions 0 -diameterServerSessions 0 $KINDNESS $TRACING &
121     ;;
122
123 esac
124
125 echo
126 echo "Created 'run.sh' script !"
127 echo