remove invocation of push-policies.sh in legacy pap
[policy/engine.git] / packages / docker / src / main / docker / do-start.sh
1 #!/bin/bash
2 #
3 #============LICENSE_START==================================================
4 #  ONAP Policy Engine
5 #===========================================================================
6 #  Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
7 #===========================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #         http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #============LICENSE_END==================================================
20 #
21
22
23 # Script to configure and start the Policy components that are to run in the designated container,
24 # It is intended to be used as the entrypoint in the Dockerfile, so the last statement of the
25 # script just goes into a long sleep so that the script does not exit (which would cause the
26 # container to be torn down).
27
28 container=$1
29
30 case $container in
31 pap)
32         comps="base pap paplp console mysql elk"
33         ;;
34 pdp)
35         comps="base pdp pdplp"
36         ;;
37 brmsgw)
38         comps="base brmsgw"
39         ;;
40 *)
41         echo "Usage: do-start.sh pap|pdp|brmsgw" >&2
42         exit 1
43 esac
44
45
46 # skip installation if build.info file is present (restarting an existing container)
47 if [[ -f /opt/app/policy/etc/build.info ]]; then
48         echo "Found existing installation, will not reinstall"
49         . /opt/app/policy/etc/profile.d/env.sh
50
51 else
52         if [[ -d config ]]; then
53                 cp config/*.conf .
54         fi
55
56         for comp in $comps; do
57                 echo "Installing component: $comp"
58                 ./docker-install.sh --install $comp
59         done
60         for comp in $comps; do
61                 echo "Configuring component: $comp"
62                 ./docker-install.sh --configure $comp
63         done
64
65         . /opt/app/policy/etc/profile.d/env.sh
66
67         # override the policy keystore and truststore if present
68
69         if [[ -f config/policy-keystore ]]; then
70             cp config/policy-keystore $POLICY_HOME/etc/ssl
71         fi
72
73         if [[ -f config/policy-truststore ]]; then
74             cp -f config/policy-trustore ${POLICY_HOME}/etc/ssl
75         fi
76
77         if [[ -f config/$container-tweaks.sh ]] ; then
78                 # file may not be executable; running it as an
79                 # argument to bash avoids needing execute perms.
80                 bash config/$container-tweaks.sh
81         fi
82
83         if [[ $container == pap ]]; then
84                 # wait for DB up
85                 ./wait-for-port.sh mariadb 3306
86                 # now that DB is up, invoke database upgrade
87                 # (which does nothing if the db is already up-to-date)
88                 dbuser=$(echo $(grep '^JDBC_USER=' base.conf | cut -f2 -d=))
89                 dbpw=$(echo $(grep '^JDBC_PASSWORD=' base.conf | cut -f2 -d=))
90                 db_upgrade_remote.sh $dbuser $dbpw mariadb
91         fi
92
93 fi
94
95 # pap needs to wait for mariadb up before starting;
96 # others need to wait for pap up (in case it had to do db upgrade)
97 if [[ $container == pap ]]; then
98         # we may have already done this above, but doesn't hurt to repeat
99         ./wait-for-port.sh mariadb 3306
100 else
101         ./wait-for-port.sh pap 9091
102 fi
103
104 policy.sh start
105
106 # on pap, wait for pap, pdp, brmsgw, nexus and drools up,
107 # then push the initial default policies
108 if [[ $container == pap ]]; then
109         ./wait-for-port.sh pap 9091
110         ./wait-for-port.sh pdp 8081
111         # brmsgw doesn't have a REST API, so check for JMX port instead
112         ./wait-for-port.sh brmsgw 9989
113         ./wait-for-port.sh nexus 8081
114         ./wait-for-port.sh drools 6969
115 fi
116
117 sleep infinity