0e473105a2b709d04382189daf30e1a75aed89a7
[oom.git] / kubernetes / policy / charts / policy-common / resources / config / scripts / do-start.sh
1 # Copyright © 2017 Amdocs, Bell Canada, AT&T
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 #!/bin/bash
16
17 # Script to configure and start the Policy components that are to run in the designated container,
18 # It is intended to be used as the entrypoint in the Dockerfile, so the last statement of the
19 # script just goes into a long sleep so that the script does not exit (which would cause the
20 # container to be torn down).
21
22 container=$1
23
24 case $container in
25 pap)
26         comps="base pap paplp console mysql elk"
27         ;;
28 pdp)
29         comps="base pdp pdplp"
30         ;;
31 brmsgw)
32         comps="base brmsgw"
33         ;;
34 *)
35         echo "Usage: do-start.sh pap|pdp|brmsgw" >&2
36         exit 1
37 esac
38
39
40 # skip installation if build.info file is present (restarting an existing container)
41 if [[ -f /opt/app/policy/etc/build.info ]]; then
42         echo "Found existing installation, will not reinstall"
43         . /opt/app/policy/etc/profile.d/env.sh
44
45 else
46         if [[ -d config ]]; then
47                 cp config/*.conf .
48         fi
49
50         for comp in $comps; do
51                 echo "Installing component: $comp"
52                 ./docker-install.sh --install $comp
53         done
54         for comp in $comps; do
55                 echo "Configuring component: $comp"
56                 ./docker-install.sh --configure $comp
57         done
58
59         . /opt/app/policy/etc/profile.d/env.sh
60
61         # install keystore
62         # override the policy keystore and truststore if present
63         if [[ -f config/policy-keystore ]]; then
64                 cp config/policy-keystore $POLICY_HOME/etc/ssl
65         fi
66
67         if [[ -f config/policy-truststore ]]; then
68                 cp -f config/policy-truststore $[POLICY_HOME]/etc/ssl
69         fi
70
71         if [[ -f config/$container-tweaks.sh ]] ; then
72                 # file may not be executable; running it as an
73                 # argument to bash avoids needing execute perms.
74                 bash config/$container-tweaks.sh
75         fi
76
77         if [[ $container == pap ]]; then
78                 # wait for DB up
79                 # now that DB is up, invoke database upgrade
80                 # (which does nothing if the db is already up-to-date)
81                 if [[ -v JDBC_USER ]]; then
82                         dbuser=${JDBC_USER};
83                 else
84                         dbuser=$(echo $(grep '^JDBC_USER=' base.conf | cut -f2 -d=))
85                 fi
86
87                 if [[ -v JDBC_PASSWORD ]]; then
88                         dbpw=${JDBC_PASSWORD}
89                 else
90                         dbpw=$(echo $(grep '^JDBC_PASSWORD=' base.conf | cut -f2 -d=))
91                 fi
92                 db_upgrade_remote.sh $dbuser $dbpw {{.Values.global.mariadb.service.name}}
93         fi
94
95 fi
96
97 policy.sh start
98
99 # on pap, wait for pap, pdp, brmsgw, nexus and drools up,
100 # then push the initial default policies
101 if [[ $container == pap ]]; then
102         # wait addional 1 minute for all processes to get fully initialized and synched up
103         sleep 60
104         bash -xv config/push-policies.sh
105 fi
106
107 sleep 1000d