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