Project

General

Profile

start_server.sh

Roger Borrello, 05/18/2023 09:09 AM

Download (3.66 KB)

 
1
#!/bin/bash
2

    
3
# default values
4
dbrestore=false
5
prepare_dir=false
6
prep_cfg="bmsdev-merged.txt"
7
which_db="default"
8

    
9
i=0
10
i=$((i+1)); usage[$i]="Usage: $0 [-cd] [-r [report_testing]] [-p<cfg>]"
11
i=$((i+1)); usage[$i]="Where:"
12
i=$((i+1)); usage[$i]="\t c = Clear log files"
13
i=$((i+1)); usage[$i]="\t r = Restore database. Specify -r report_testing to restore that DB or else the default"
14
i=$((i+1)); usage[$i]="\t d = Run server with debug enabled"
15
i=$((i+1)); usage[$i]="\t p = Perform directory preparation using <cfg> (eg. specify -p$prep_cfg for cfgs/$prep_cfg)"
16

    
17
show_usage()
18
{
19
   for i in "${usage[@]}"; do
20
      echo -e $i
21
   done
22
}
23

    
24
# Sanity check to see if server is already running
25
./server.sh -s | grep STATUS_RUNNING > /dev/null 2>&1
26
rc=$?
27
if [ $rc -eq 0 ]; then
28
   echo "Server is *already* running. If you want to restart, use ./stop_server.sh first."
29
   exit 0
30
fi
31

    
32
# process options
33
while getopts "h?crdp:" opt; do
34
   case $opt in
35
      c  ) rm -f ./*.log* /usr/c-act/*.log* /usr/c-act/logs/*.log*
36
           ;;
37
      r  ) dbrestore=true
38
           # Check next positional parameter
39
           eval nextopt=\${$OPTIND}
40
           # existing or starting with dash?
41
           if [[ -n $nextopt && $nextopt != -* ]]; then
42
              OPTIND=$((OPTIND + 1))
43
              which_db=$nextopt
44
           fi
45
           ;;
46
      d  ) dbug="-d"
47
           ;;
48
      p  ) prepare_dir=true
49
           if [ -n $OPTARG ]; then prep_cfg=$OPTARG; fi
50
           ;;
51
      h | \
52
      \? ) show_usage && exit 1
53
           ;;
54
   esac
55
done
56
shift $(($OPTIND - 1))
57

    
58
if [ "$dbrestore" = true ]; then
59
   echo "** Restoring $which_db DB ..."
60
   pushd ../.. > /dev/null
61
   if [[ "$which_db" = "report_testing" ]] && [[ -d "data/dump_report_testing" ]]; then # We need to swap it
62
      swapem=true
63
      echo "** Swapping default and report_testing DB ..."
64
      mv data/dump data/dump.ori
65
      mv data/dump_report_testing data/dump
66
   fi
67
   ant import.db
68
   if [ $? -ne 0 ]; then
69
      rval=$?
70
      echo "** Master DB restore has failed!"
71
      impfail=true
72
   fi
73
   if [ "$swapem" = true ]; then
74
      echo "** Un-swapping default and report_testing DB ..."
75
      mv data/dump data/dump_report_testing
76
      mv data/dump.ori data/dump
77
   fi
78
   popd > /dev/null
79
   if [ "$impfail" = true ]; then
80
      exit rval
81
   fi
82
else
83
   echo "** Not performing master DB restore."
84
fi
85

    
86
if [ "$prepare_dir" = true ]; then
87
   # Setup templates if we are restoring a fresh database, otherwise just leave the configuration alone
88
   # This means it is up to the user to configure their directory.xml files prior to running.
89
   if [ -f "cfgs/$prep_cfg" ]; then
90
      ./prepare_dir.sh <cfgs/$prep_cfg
91
   else
92
      echo "** Cannot locate cfgs/$prep_cfg for directory prepare!"
93
      exit 1
94
   fi
95
   if [ $? -ne 0 ]; then
96
      echo "** Directory prepare has failed!"
97
      exit $?
98
   fi
99
else   
100
   echo "** Bypassing directory preparation."
101
fi   
102

    
103
echo "** Starting server..."
104
./server.sh $dbug &
105

    
106
echo "** Waiting for server to start..."
107
./server.sh -w
108
server_ready=$?
109

    
110
if [ $server_ready -ne 0 ]; then
111
   echo "Server could not be started!"
112
   exit 1
113
else
114
   # Secondary wait for appservers. Messages are:
115
   echo "** Initial server startup complete. Awaiting app servers..."
116
   apps_cact=" Appserver 'cactAS1' was started successfully ("
117
   apps_mob=" Appserver 'mobAS1' was started successfully ("
118
   logfile=/usr/c-act/logs/server_0.log
119
   cnt=0
120
   tail -f $logfile |
121
   while IFS= read line; 
122
   do
123
      if [[ "$line" == *"$apps_cact"* ]] || [[ "$line" == *"$apps_mob"* ]]; then
124
         cnt=$((cnt+1))
125
         echo "...Appserver $cnt found"
126
      fi
127
      if [ $cnt -eq 2 ]; then
128
         pkill tail;
129
      fi;
130
   done
131

    
132
   echo "** Server started successfully!"
133
fi
134

    
135
exit 0