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