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