40008f9e68d3b8219d2d56a52143ed7e7ebdc5d5
[ric-app/mc.git] / mc-core / container_start.sh
1 #!/usr/bin/env bash
2 # vim: ts=4 sw=4 noet:
3 #----------------------------------------------------------------------------------
4 #
5 #       Copyright (c) 2018-2020 AT&T Intellectual Property.
6 #
7 #   Licensed under the Apache License, Version 2.0 (the "License");
8 #   you may not use this file except in compliance with the License.
9 #   You may obtain a copy of the License at
10 #
11 #          http://www.apache.org/licenses/LICENSE-2.0
12 #
13 #   Unless required by applicable law or agreed to in writing, software
14 #   distributed under the License is distributed on an "AS IS" BASIS,
15 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #   See the License for the specific language governing permissions and
17 #   limitations under the License.
18 #
19 #---------------------------------------------------------------------------------
20
21
22 # ----------------------------------------------------------------------
23 # Mnemonic:     container_start.sh
24 # Abstract: For some "pod" environments a single container is required.
25 #                       This starts all of the related processes which normally would
26 #                       be started in individual containers.
27 #
28 #                       There are environment variables which affect the operation
29 #                       of this script:
30 #
31 #                               GSLITE_ROOT -- Assumed to be the root directory for the
32 #                                                       core MC xAPP. If not defined, /mc/gs-lite is
33 #                                                       assumed.
34 #
35 #                       When NOT running in simulation mode, a registration message is
36 #                       sent to the xAPP manager via the registration script in /playpen.
37 #                       An unregister message is "queued" and should be sent when this
38 #                       script receives a terminating event, or exits normally.
39 #
40 # Date:         13 February 2019
41 # Author:       E. Scott Daniels
42 # ----------------------------------------------------------------------
43
44 # MUST have a posix style function declaration!
45 unreg() {
46         trap - EXIT                                             # prevent running this again when we force the exit
47         /playpen/bin/xam_register -U
48         exit
49 }
50
51 set -e
52
53 FIFO_DIR="/tmp/mcl/fifos"
54
55 SIMULATOR_MODE=`python /mc/extract_params.py ${XAPP_DESCRIPTOR_PATH}/config-file.json simulator_mode`
56 RMR_PORT=`python /mc/extract_rmr_port.py ${XAPP_DESCRIPTOR_PATH}/config-file.json rmr-data`
57
58 mkdir -p $FIFO_DIR
59
60 if [ "$SIMULATOR_MODE" != "true" ]
61 then
62         # --- start "sidecars" first. They are expected to need /playpen as the working dir
63
64         (
65                 cd /playpen
66                 if [ "$RMR_PORT" != "" ]
67                 then
68                         bin/mc_listener -p $RMR_PORT
69                 else
70                         bin/mc_listener
71                 fi
72         ) >/tmp/listener.std 2>&1 &
73
74         echo "listener was started" >&2
75
76         trap 'unreg' EXIT 1 2 3 4 15                            # unregister on exit/hup/quit/term
77         /playpen/bin/xam_register.sh                            # register the xapp now that listener is up
78 fi
79
80
81 # ---- finally, start the core MC application -----------------------------
82 cd ${GSLITE_ROOT:-/mc/gs-lite}/demo/queries
83 ./runall
84