Add DCAE MOD design tool project
[dcaegen2/platform.git] / mod / designtool / designtool-web / sh / start.sh
1 #!/bin/sh -e
2
3 #    Licensed to the Apache Software Foundation (ASF) under one or more
4 #    contributor license agreements.  See the NOTICE file distributed with
5 #    this work for additional information regarding copyright ownership.
6 #    The ASF licenses this file to You under the Apache License, Version 2.0
7 #    (the "License"); you may not use this file except in compliance with
8 #    the License.  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 #    Modifications to the original nifi code for the ONAP project are made
20 #    available under the Apache License, Version 2.0
21 #
22
23 scripts_dir='/opt/nifi/scripts'
24
25 [ -f "${scripts_dir}/common.sh" ] && . "${scripts_dir}/common.sh"
26
27 # Establish baseline properties
28 prop_replace 'nifi.web.http.port'               "${NIFI_WEB_HTTP_PORT:-8080}"
29 prop_replace 'nifi.web.http.host'               "${NIFI_WEB_HTTP_HOST:-$HOSTNAME}"
30 prop_replace 'nifi.remote.input.host'           "${NIFI_REMOTE_INPUT_HOST:-$HOSTNAME}"
31 prop_replace 'nifi.remote.input.socket.port'    "${NIFI_REMOTE_INPUT_SOCKET_PORT:-10000}"
32 prop_replace 'nifi.remote.input.secure'         'false'
33
34 # Set nifi-toolkit properties files and baseUrl
35 "${scripts_dir}/toolkit.sh"
36 prop_replace 'baseUrl' "http://${NIFI_WEB_HTTP_HOST:-$HOSTNAME}:${NIFI_WEB_HTTP_PORT:-8080}" ${nifi_toolkit_props_file}
37
38 prop_replace 'nifi.variable.registry.properties'    "${NIFI_VARIABLE_REGISTRY_PROPERTIES:-}"
39 prop_replace 'nifi.cluster.is.node'                         "${NIFI_CLUSTER_IS_NODE:-false}"
40 prop_replace 'nifi.cluster.node.address'                    "${NIFI_CLUSTER_ADDRESS:-$HOSTNAME}"
41 prop_replace 'nifi.cluster.node.protocol.port'              "${NIFI_CLUSTER_NODE_PROTOCOL_PORT:-}"
42 prop_replace 'nifi.cluster.node.protocol.threads'           "${NIFI_CLUSTER_NODE_PROTOCOL_THREADS:-10}"
43 prop_replace 'nifi.cluster.node.protocol.max.threads'       "${NIFI_CLUSTER_NODE_PROTOCOL_MAX_THREADS:-50}"
44 prop_replace 'nifi.zookeeper.connect.string'                "${NIFI_ZK_CONNECT_STRING:-}"
45 prop_replace 'nifi.zookeeper.root.node'                     "${NIFI_ZK_ROOT_NODE:-/nifi}"
46 prop_replace 'nifi.cluster.flow.election.max.wait.time'     "${NIFI_ELECTION_MAX_WAIT:-5 mins}"
47 prop_replace 'nifi.cluster.flow.election.max.candidates'    "${NIFI_ELECTION_MAX_CANDIDATES:-}"
48 prop_replace 'nifi.web.proxy.context.path'                  "${NIFI_WEB_PROXY_CONTEXT_PATH:-}"
49
50 # REVIEW: Could not figure out how the nifi.properties file gets generated so
51 # replace value conditionally if the property name exists otherwise append
52 if grep -q 'nifi.dcae.jars.index.url' $nifi_props_file
53 then
54     prop_replace 'nifi.dcae.jars.index.url'                     "${NIFI_DCAE_JARS_INDEX_URL:-http://genprocessor-http/nifi-jars/}"
55 else
56     prop_append 'nifi.dcae.jars.index.url'                     "${NIFI_DCAE_JARS_INDEX_URL:-http://genprocessor-http/nifi-jars/}"
57 fi
58
59 if grep -q 'nifi.ui.dcae.distibutor.api.url' $nifi_props_file
60 then
61     prop_replace 'nifi.ui.dcae.distibutor.api.url' "${NIFI_DCAE_DISTRIBUTOR_API_URL:-http://distributor-api}"
62 else
63     prop_append 'nifi.ui.dcae.distibutor.api.url' "${NIFI_DCAE_DISTRIBUTOR_API_URL:-http://distributor-api}"
64 fi
65
66 . "${scripts_dir}/update_cluster_state_management.sh"
67
68 # Check if we are secured or unsecured
69 case ${AUTH} in
70     tls)
71         echo 'Enabling Two-Way SSL user authentication'
72         . "${scripts_dir}/secure.sh"
73         ;;
74     ldap)
75         echo 'Enabling LDAP user authentication'
76         # Reference ldap-provider in properties
77         prop_replace 'nifi.security.user.login.identity.provider' 'ldap-provider'
78
79         . "${scripts_dir}/secure.sh"
80         . "${scripts_dir}/update_login_providers.sh"
81         ;;
82     *)
83         if [ ! -z "${NIFI_WEB_PROXY_HOST}" ]; then
84             echo 'NIFI_WEB_PROXY_HOST was set but NiFi is not configured to run in a secure mode.  Will not update nifi.web.proxy.host.'
85         fi
86         ;;
87 esac
88
89 # Continuously provide logs so that 'docker logs' can    produce them
90 tail -F "${NIFI_HOME}/logs/nifi-app.log" &
91 "${NIFI_HOME}/bin/nifi.sh" run &
92 nifi_pid="$!"
93
94 trap "echo Received trapped signal, beginning shutdown...;" KILL TERM HUP INT EXIT;
95
96 echo NiFi running with PID ${nifi_pid}.
97 wait ${nifi_pid}