522eaf2a67d2888de271dad3e8d67196f98fd478
[portal.git] / deliveries / start-apache-tomcat.sh
1 #!/bin/sh
2 # Starts the Apache-Tomcat web container.
3 # If arguments "-i ip.2.3.4" AND "-n name" are present, adds an entry to /etc/hosts;
4 # this was added as a workaround for missing DNS in the CSIT environment.
5
6 hostip=""
7 hostname=""
8 while [ $# -gt 0 ]; do
9     key="$1"
10     case $key in
11         -i|--ip)
12         hostip="$2"
13         echo "$0: option -i value is $hostip"
14         shift # past argument
15         shift # past value
16         ;;
17         -n|--name)
18         hostname="$2"
19         echo "$0: option -n value is $hostname"
20         shift # past argument
21         shift # past value
22         ;;
23         *)
24         echo "$0: ignoring argument $key"
25         shift
26         ;;
27     esac
28 done
29
30 # Optionally add to /etc/hosts
31 # Docker-compose supplies arguments ""
32 if [ ${#hostip} -lt 3 -o ${#hostname} -lt 3 ]; then
33     echo "$0: values for IP (-i) and/or name (-n) are empty or short"
34 else
35     echo "$0: using IP-name arguments $hostip $hostname"
36     grep $hostname /etc/hosts
37     ret_code=$?
38     if [ $ret_code != 0 ]; then
39         echo "$0: extending hosts with $hostname"
40         echo "$hostip $hostname" >> /etc/hosts
41     else
42         echo "$0: hosts already has $hostname"
43     fi
44 fi
45
46 BASE=/opt/apache-tomcat-8.0.37
47 if [ ! -d $BASE ] ; then
48     echo "$0: $BASE not found or not a directory"
49     exit 1
50 fi
51 echo "$0: Starting server from $BASE"
52 LOGFILE=${BASE}/logs/catalina.out
53 echo "`date`:<--------------------    Starting     -------------------->" >> $LOGFILE
54 exec ${BASE}/bin/catalina.sh run  2>&1 | tee -a $LOGFILE