blob: f26b32520fa9d4bcb8b59c6a844445dde942d433 [file] [log] [blame]
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -04001#!/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
19usage() {
Jeremy Mordkoff03156e32017-09-30 21:42:44 -040020 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>]"
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040021}
22
23function handle_received_signal() {
24 forever stopall
25 echo "Stopped Skyquake and API servers started with forever"
26 exit
27}
28
Jeremy Mordkoff03156e32017-09-30 21:42:44 -040029# Gets the current hosts ip/fqdn. If the host is resolvable through dns, it
30# returns the fqdn else returns the ip address.
31get_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}
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040040
41start_servers() {
42 cd $THIS_DIR
43 echo "Stopping any previous instances of Skyquake and API servers started with forever"
44 forever stopall
45
Jeremy Mordkoff03156e32017-09-30 21:42:44 -040046 local launchpad_address=$(get_host_address)
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040047
Jeremy Mordkoff03156e32017-09-30 21:42:44 -040048 echo "Running Node.js Skyquake server. HTTPS Enabled: ${ENABLE_HTTPS}, Launchpad Address: ${launchpad_address}"
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040049 cd ..
50 if [ ! -z "${ENABLE_HTTPS}" ]; then
Jeremy Mordkoff03156e32017-09-30 21:42:44 -040051 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}"
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040052 else
Jeremy Mordkoff03156e32017-09-30 21:42:44 -040053 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}"
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040054 fi
55}
56
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040057# Begin work
58for i in "$@"
59do
60case $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 ;;
Jeremy Mordkoff03156e32017-09-30 21:42:44 -040069 -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 ;;
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -040081 -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 ;;
92esac
93done
94
95if [[ ! -z "${ENABLE_HTTPS}" ]]; then
96 if [ -z "${KEYFILE_PATH}" ] || [ -z "${CERTFILE_PATH}" ]; then
97 usage
98 exit
99 fi
100fi
101
102
103# change to the directory of this script
104THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
105
Jeremy Mordkoff03156e32017-09-30 21:42:44 -0400106cd $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
Jeremy Mordkoffe29efc32016-09-07 18:59:17 -0400110
111# Call function to start web and API servers
112start_servers
113
114
115# Ensure that the forever script is stopped when this script exits
116trap "echo \"Received EXIT\"; handle_received_signal" EXIT
117trap "echo \"Received SIGINT\"; handle_received_signal" SIGINT
118trap "echo \"Received SIGKILL\"; handle_received_signal" SIGKILL
119trap "echo \"Received SIGABRT\"; handle_received_signal" SIGABRT
120trap "echo \"Received SIGQUIT\"; handle_received_signal" SIGQUIT
121trap "echo \"Received SIGSTOP\"; handle_received_signal" SIGSTOP
122trap "echo \"Received SIGTERM\"; handle_received_signal" SIGTERM
123trap "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.
127while true; do
128 sleep 5
129done