Revert "BUG-410 -- update RIFT platform"
[osm/UI.git] / skyquake / scripts / launch_ui.sh
1 #!/bin/bash
2
3 #
4 # Copyright 2016 RIFT.IO Inc
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # 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 usage() {
20 echo "usage: launch_ui.sh --launchpad-address=<ip_or_fqdn> --idp-port-number=<port_number> [--enable-https --keyfile-path=<keyfile_path> --certfile-path=<certfile-path>]"
21 }
22
23 function handle_received_signal() {
24 forever stopall
25 echo "Stopped Skyquake and API servers started with forever"
26 exit
27 }
28
29 # Gets the current hosts ip/fqdn. If the host is resolvable through dns, it
30 # returns the fqdn else returns the ip address.
31 get_host_address() {
32 if [[ -z $(hostname -d) ]]; then
33 # not resolvable via dns, use resolvable ip address
34 echo $(hostname --ip-address)
35 else
36 # use the fqdn
37 echo $(hostname --fqdn)
38 fi
39 }
40
41 start_servers() {
42 cd $THIS_DIR
43 echo "Stopping any previous instances of Skyquake and API servers started with forever"
44 forever stopall
45
46 local launchpad_address=$(get_host_address)
47
48 echo "Running Node.js Skyquake server. HTTPS Enabled: ${ENABLE_HTTPS}, Launchpad Address: ${launchpad_address}"
49 cd ..
50 if [ ! -z "${ENABLE_HTTPS}" ]; then
51 forever start -a -l forever.log -o out.log -e err.log skyquake.js --enable-https --keyfile-path="${KEYFILE_PATH}" --certfile-path="${CERTFILE_PATH}" --launchpad-address="${LAUNCHPAD_ADDRESS}" --idp-port-number="${IDP_PORT_NUMBER}" --callback-address="${CALLBACK_ADDRESS}"
52 else
53 forever start -a -l forever.log -o out.log -e err.log skyquake.js --launchpad-address="${LAUNCHPAD_ADDRESS}" --idp-port-number="${IDP_PORT_NUMBER}" --callback-address="${CALLBACK_ADDRESS}"
54 fi
55 }
56
57 # Begin work
58 for i in "$@"
59 do
60 case $i in
61 -k=*|--keyfile-path=*)
62 KEYFILE_PATH="${i#*=}"
63 shift # past argument=value
64 ;;
65 -c=*|--certfile-path=*)
66 CERTFILE_PATH="${i#*=}"
67 shift # past argument=value
68 ;;
69 -l=*|--launchpad-address=*)
70 LAUNCHPAD_ADDRESS="${i#*=}"
71 shift # past argument=value
72 ;;
73 -p=*|--idp-port-number=*)
74 IDP_PORT_NUMBER="${i#*=}"
75 shift # past argument=value
76 ;;
77 -r=*|--callback-address=*)
78 CALLBACK_ADDRESS="${i#*=}"
79 shift # past argument=value
80 ;;
81 -h|--help)
82 usage
83 exit
84 ;;
85 -e|--enable-https)
86 ENABLE_HTTPS=YES
87 shift # past argument=value
88 ;;
89 *)
90 # unknown option
91 ;;
92 esac
93 done
94
95 if [[ ! -z "${ENABLE_HTTPS}" ]]; then
96 if [ -z "${KEYFILE_PATH}" ] || [ -z "${CERTFILE_PATH}" ]; then
97 usage
98 exit
99 fi
100 fi
101
102
103 # change to the directory of this script
104 THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
105
106 cd $THIS_DIR
107
108 # Call script to handle tarred node_modules as cpack+RPM cannot handle a lot of files
109 $THIS_DIR/handle_plugin_node_modules
110
111 # Call function to start web and API servers
112 start_servers
113
114
115 # Ensure that the forever script is stopped when this script exits
116 trap "echo \"Received EXIT\"; handle_received_signal" EXIT
117 trap "echo \"Received SIGINT\"; handle_received_signal" SIGINT
118 trap "echo \"Received SIGKILL\"; handle_received_signal" SIGKILL
119 trap "echo \"Received SIGABRT\"; handle_received_signal" SIGABRT
120 trap "echo \"Received SIGQUIT\"; handle_received_signal" SIGQUIT
121 trap "echo \"Received SIGSTOP\"; handle_received_signal" SIGSTOP
122 trap "echo \"Received SIGTERM\"; handle_received_signal" SIGTERM
123 trap "echo \"Received SIGTRAP\"; handle_received_signal" SIGTRAP
124
125 # Keep this script in the foreground so the system doesn't think that the
126 # server crashed.
127 while true; do
128 sleep 5
129 done