blob: 9268bed288349228d1e33249606429c492811211 [file] [log] [blame]
Michael Blow6214f6f2016-08-31 03:03:00 -04001#!/bin/bash
2# ------------------------------------------------------------
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance
9# with the License. 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,
14# software distributed under the License is distributed on an
15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16# KIND, either express or implied. See the License for the
17# specific language governing permissions and limitations
18# under the License.
19# ------------------------------------------------------------
20
Michael Blowfec04f02016-10-27 21:15:20 -040021function usage() {
22 echo
Michael Blowfab68d22019-04-12 12:48:53 -040023 echo Usage: $(basename $0)
Michael Blowfec04f02016-10-27 21:15:20 -040024 echo
Michael Blowfec04f02016-10-27 21:15:20 -040025}
26
27while [ -n "$1" ]; do
28 case $1 in
Michael Blowfab68d22019-04-12 12:48:53 -040029 -f|-force);; # ignored, this is always the case
Michael Blowfec04f02016-10-27 21:15:20 -040030 -help|--help|-usage|--usage) usage; exit 0;;
31 *) echo "ERROR: unknown argument '$1'"; usage; exit 1;;
32 esac
33 shift
34done
35
Michael Blow6214f6f2016-08-31 03:03:00 -040036if [ -z "$JAVA_HOME" -a -x /usr/libexec/java_home ]; then
37 JAVA_HOME=$(/usr/libexec/java_home)
38 export JAVA_HOME
39fi
40
Ian Maxon2b3681f2018-05-09 14:25:16 -070041# OS specific support. $var _must_ be set to either true or false.
42cygwin=false;
43darwin=false;
44case "`uname`" in
45 CYGWIN*) cygwin=true ;;
46 Darwin*) darwin=true
47 if [ -z "$JAVA_VERSION" ] ; then
48 JAVA_VERSION="CurrentJDK"
49 else
50 echo "Using Java version: $JAVA_VERSION"
51 fi
52 if [ -z "$JAVA_HOME" ]; then
53 if [ -x "/usr/libexec/java_home" ]; then
54 JAVA_HOME=`/usr/libexec/java_home`
55 else
56 JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
57 fi
58 fi
59 ;;
60esac
61
62if [ -z "$JAVA_HOME" ] ; then
63 if [ -r /etc/gentoo-release ] ; then
64 JAVA_HOME=`java-config --jre-home`
65 fi
66fi
67
68# For Cygwin, ensure paths are in UNIX format before anything is touched
69if $cygwin ; then
70 [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
71 [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
72fi
73
74# If a specific java binary isn't specified search for the standard 'java' binary
75if [ -z "$JAVACMD" ] ; then
76 if [ -n "$JAVA_HOME" ] ; then
77 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
78 # IBM's JDK on AIX uses strange locations for the executables
79 JAVACMD="$JAVA_HOME/jre/sh/java"
80 else
81 JAVACMD="$JAVA_HOME/bin/java"
82 fi
83 else
84 JAVACMD=`which java`
85 fi
86fi
87
Michael Blow55431322019-02-15 19:06:27 -050088export JAVA_VERSION=$($JAVACMD -version 2>&1 | head -1 | awk '{ print $3 }' | tr -d '"')
Michael Blow4dad0132018-06-08 14:26:11 -040089case $JAVA_VERSION in
90 1.8*|1.9*|10*|11*)
91 ;;
92 *)
93 echo JAVA_HOME must be at version 1.8 or later, but is: $JAVA_VERSION
Michael Blow6214f6f2016-08-31 03:03:00 -040094 exit 2
Michael Blow4dad0132018-06-08 14:26:11 -040095esac
96
Michael Blowd0324c22017-05-12 21:43:02 -040097DIRNAME=$(dirname "$0")
Michael Blow6214f6f2016-08-31 03:03:00 -040098[ $(echo $DIRNAME | wc -l) -ne 1 ] && {
99 echo "Paths with spaces are not supported"
100 exit 3
101}
102
Michael Blowd0324c22017-05-12 21:43:02 -0400103CLUSTERDIR=$(cd "$DIRNAME/.."; echo $PWD)
104INSTALLDIR=$(cd "$CLUSTERDIR/../.."; echo $PWD)
Michael Blow6214f6f2016-08-31 03:03:00 -0400105LOGSDIR=$CLUSTERDIR/logs
106
107echo "CLUSTERDIR=$CLUSTERDIR"
108echo "INSTALLDIR=$INSTALLDIR"
Michael Blowfdcf0552016-09-25 22:18:27 -0400109echo "LOGSDIR=$LOGSDIR"
Michael Blow6214f6f2016-08-31 03:03:00 -0400110echo
Michael Blowd0324c22017-05-12 21:43:02 -0400111cd "$CLUSTERDIR"
112mkdir -p "$LOGSDIR"
113"$INSTALLDIR/bin/${HELPER_COMMAND}" get_cluster_state -quiet \
Michael Blow6214f6f2016-08-31 03:03:00 -0400114 && echo "ERROR: sample cluster address (localhost:${LISTEN_PORT}) already in use" && exit 1
115
Michael Blowefe014d2017-03-09 22:09:20 -0500116if ps -ef | grep 'java.*org\.apache\.hyracks\.control\.[cn]c\.\([CN]CDriver\|service\.NCService\)' > /tmp/$$_pids; then
Michael Blowfab68d22019-04-12 12:48:53 -0400117 echo "WARNING: ${PRODUCT} processes are already running:"
118 cat /tmp/$$_pids | sed 's/^ *[0-9]* \([0-9]*\).*org\.apache\.hyracks\.control\.[cn]c[^ ]*\.\([^ ]*\) .*/\1 - \2/'
119 rm /tmp/$$_pids
Michael Blowfec04f02016-10-27 21:15:20 -0400120fi
121
Michael Blowefe014d2017-03-09 22:09:20 -0500122rm /tmp/$$_pids
Michael Blow6214f6f2016-08-31 03:03:00 -0400123(
124 echo "--------------------------"
125 date
126 echo "--------------------------"
Michael Blowd0324c22017-05-12 21:43:02 -0400127) | tee -a "$LOGSDIR/blue-service.log" | tee -a "$LOGSDIR/red-service.log" >> "$LOGSDIR/cc.log"
Michael Blowfec04f02016-10-27 21:15:20 -0400128echo "INFO: Starting sample cluster..."
Michael Blowd0324c22017-05-12 21:43:02 -0400129"$INSTALLDIR/bin/${NC_SERVICE_COMMAND}" -logdir - -config-file "$CLUSTERDIR/conf/blue.conf" >> "$LOGSDIR/blue-service.log" 2>&1 &
130"$INSTALLDIR/bin/${NC_SERVICE_COMMAND}" -logdir - >> "$LOGSDIR/red-service.log" 2>&1 &
131"$INSTALLDIR/bin/${CC_COMMAND}" -config-file "$CLUSTERDIR/conf/cc.conf" >> "$LOGSDIR/cc.log" 2>&1 &
132"$INSTALLDIR/bin/${HELPER_COMMAND}" wait_for_cluster -timeout 30
Michael Blowfdcf0552016-09-25 22:18:27 -0400133exit $?