#!/bin/bash ################################################################################ # HPCC SYSTEMS software Copyright (C) 2018 HPCC Systems®. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ source @INSTALL_DIR@/etc/init.d/hpcc_common set_environmentvars source @ADMIN_PATH@/hpcc_setenv "" component=$(basename ${PWD}) logpthtail="$(date +%Y_%m_%d_%H_%M_%S)" export logfile="@LOG_PATH@/${component}/${component}_${logpthtail}.log" log "Writing out pid file" echo "$$" > @PID_PATH@/init_${component}.pid log "mimicing sentinel file" echo "rerun" > sparkthor.sentinel function wait_external() { local pid=$1 while [[ 1 ]]; do if kill -0 ${pid}; then sleep 30 else break fi done } function terminate() { log "Terminating children of init_sparkthor ${component}" @ADMIN_PATH@/sparkthor.sh stop ${component} #pkill -P $$ rm -f sparkthor.sentinel exit 0 } trap "terminate" SIGINT SIGTERM while [[ 1 ]]; do if [[ -e @PID_PATH@/${component}.pid ]]; then _master_pid="$(cat @PID_PATH@/${component}.pid)" if ! kill -0 ${_master_pid}; then log "spark master not running, attempting restart of ${component}" @ADMIN_PATH@/sparkthor.sh start ${component} ln -s -T @PID_PATH@/spark-hpcc-org.apache.spark.deploy.master.Master-1.pid @PID_PATH@/${component}.pid fi else log "Starting spark master ${component}" @ADMIN_PATH@/sparkthor.sh start ${component} ln -s -T @PID_PATH@/spark-hpcc-org.apache.spark.deploy.master.Master-1.pid @PID_PATH@/${component}.pid fi _master_pid="$(cat @PID_PATH@/${component}.pid)" log "waiting on spark master process :: ${_master_pid}" wait_external $_master_pid done