614ad1e89bcdd2846730d789726ee2b87c44e476
[policy/engine.git] / packages / docker / src / main / docker / do-start.sh
1 #!/bin/bash
2
3 # Script to configure and start the Policy components that are to run in the designated container,
4 # It is intended to be used as the entrypoint in the Dockerfile, so the last statement of the
5 # script just goes into a long sleep so that the script does not exit (which would cause the
6 # container to be torn down).
7
8 container=$1
9
10 case $container in
11 pap)
12         comps="base pap paplp console mysql elk"
13         ;;
14 pdp)
15         comps="base pdp pdplp"
16         ;;
17 brmsgw)
18         comps="base brmsgw"
19         ;;
20 *)
21         echo "Usage: do-start.sh pap|pdp|brmsgw" >&2
22         exit 1
23 esac
24
25
26 # skip installation if build.info file is present (restarting an existing container)
27 if [[ -f /opt/app/policy/etc/build.info ]]; then
28         echo "Found existing installation, will not reinstall"
29         . /opt/app/policy/etc/profile.d/env.sh
30
31 else
32         if [[ -d config ]]; then
33                 cp config/*.conf .
34         fi
35
36         for comp in $comps; do
37                 echo "Installing component: $comp"
38                 ./docker-install.sh --install $comp
39         done
40         for comp in $comps; do
41                 echo "Configuring component: $comp"
42                 ./docker-install.sh --configure $comp
43         done
44
45         . /opt/app/policy/etc/profile.d/env.sh
46
47         # install policy keystore
48         mkdir -p $POLICY_HOME/etc/ssl
49         cp config/policy-keystore $POLICY_HOME/etc/ssl
50
51         if [[ -f config/$container-tweaks.sh ]] ; then
52                 # file may not be executable; running it as an
53                 # argument to bash avoids needing execute perms.
54                 bash config/$container-tweaks.sh
55         fi
56
57         if [[ $container == pap ]]; then
58                 # wait for DB up
59                 ./wait-for-port.sh mariadb 3306
60                 # now that DB is up, invoke database upgrade
61                 # (which does nothing if the db is already up-to-date)
62                 dbuser=$(echo $(grep '^JDBC_USER=' base.conf | cut -f2 -d=))
63                 dbpw=$(echo $(grep '^JDBC_PASSWORD=' base.conf | cut -f2 -d=))
64                 db_upgrade_remote.sh $dbuser $dbpw mariadb
65         fi
66
67 fi
68
69 # pap needs to wait for mariadb up before starting;
70 # others need to wait for pap up (in case it had to do db upgrade)
71 if [[ $container == pap ]]; then
72         # we may have already done this above, but doesn't hurt to repeat
73         ./wait-for-port.sh mariadb 3306
74 else
75         ./wait-for-port.sh pap 9091
76 fi
77
78 policy.sh start
79
80 # on pap, wait for pap, pdp, brmsgw, nexus and drools up,
81 # then push the initial default policies
82 if [[ $container == pap ]]; then
83         ./wait-for-port.sh pap 9091
84         ./wait-for-port.sh pdp 8081
85         # brmsgw doesn't have a REST API, so check for JMX port instead
86         ./wait-for-port.sh brmsgw 9989
87         ./wait-for-port.sh nexus 8081
88         ./wait-for-port.sh drools 6969
89         # wait addional 1 minute for all processes to get fully initialized and synched up
90         sleep 60
91         bash -xv config/push-policies.sh
92 fi
93
94 sleep 1000d