cook policy-keystore into pe image
[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-2018 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         if [[ -f config/policy-keystore ]]; then
68             # install policy keystore
69             cp config/policy-keystore $POLICY_HOME/etc/ssl
70         fi
71
72         if [[ -f config/$container-tweaks.sh ]] ; then
73                 # file may not be executable; running it as an
74                 # argument to bash avoids needing execute perms.
75                 bash config/$container-tweaks.sh
76         fi
77
78         if [[ $container == pap ]]; then
79                 # wait for DB up
80                 ./wait-for-port.sh mariadb 3306
81                 # now that DB is up, invoke database upgrade
82                 # (which does nothing if the db is already up-to-date)
83                 dbuser=$(echo $(grep '^JDBC_USER=' base.conf | cut -f2 -d=))
84                 dbpw=$(echo $(grep '^JDBC_PASSWORD=' base.conf | cut -f2 -d=))
85                 db_upgrade_remote.sh $dbuser $dbpw mariadb
86         fi
87
88 fi
89
90 # pap needs to wait for mariadb up before starting;
91 # others need to wait for pap up (in case it had to do db upgrade)
92 if [[ $container == pap ]]; then
93         # we may have already done this above, but doesn't hurt to repeat
94         ./wait-for-port.sh mariadb 3306
95 else
96         ./wait-for-port.sh pap 9091
97 fi
98
99 policy.sh start
100
101 # on pap, wait for pap, pdp, brmsgw, nexus and drools up,
102 # then push the initial default policies
103 if [[ $container == pap ]]; then
104         ./wait-for-port.sh pap 9091
105         ./wait-for-port.sh pdp 8081
106         # brmsgw doesn't have a REST API, so check for JMX port instead
107         ./wait-for-port.sh brmsgw 9989
108         ./wait-for-port.sh nexus 8081
109         ./wait-for-port.sh drools 6969
110         # wait addional 1 minute for all processes to get fully initialized and synched up
111         sleep 60
112         bash -xv config/push-policies.sh
113 fi
114
115 sleep 1000d