init_sparkthor.in 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. ################################################################################
  3. # HPCC SYSTEMS software Copyright (C) 2018 HPCC Systems®.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. ################################################################################
  17. source @INSTALL_DIR@/etc/init.d/hpcc_common
  18. set_environmentvars
  19. source @ADMIN_PATH@/hpcc_setenv ""
  20. component=$(basename ${PWD})
  21. logpthtail="$(date +%Y_%m_%d_%H_%M_%S)"
  22. export logfile="@LOG_PATH@/${component}/${component}_${logpthtail}.log"
  23. log "Writing out pid file"
  24. echo "$$" > @PID_PATH@/init_${component}.pid
  25. log "mimicing sentinel file"
  26. echo "rerun" > sparkthor.sentinel
  27. function wait_external()
  28. {
  29. local pid=$1
  30. while [[ 1 ]]; do
  31. if kill -0 ${pid}; then
  32. sleep 30
  33. else
  34. break
  35. fi
  36. done
  37. }
  38. function terminate()
  39. {
  40. log "Terminating children of init_sparkthor ${component}"
  41. @ADMIN_PATH@/sparkthor.sh stop ${component}
  42. #pkill -P $$
  43. rm -f sparkthor.sentinel
  44. exit 0
  45. }
  46. trap "terminate" SIGINT SIGTERM
  47. while [[ 1 ]]; do
  48. if [[ -e @PID_PATH@/${component}.pid ]]; then
  49. _master_pid="$(cat @PID_PATH@/${component}.pid)"
  50. if ! kill -0 ${_master_pid}; then
  51. log "spark master not running, attempting restart of ${component}"
  52. @ADMIN_PATH@/sparkthor.sh start ${component}
  53. ln -s -T @PID_PATH@/spark-hpcc-org.apache.spark.deploy.master.Master-1.pid @PID_PATH@/${component}.pid
  54. fi
  55. else
  56. log "Starting spark master ${component}"
  57. @ADMIN_PATH@/sparkthor.sh start ${component}
  58. ln -s -T @PID_PATH@/spark-hpcc-org.apache.spark.deploy.master.Master-1.pid @PID_PATH@/${component}.pid
  59. fi
  60. _master_pid="$(cat @PID_PATH@/${component}.pid)"
  61. log "waiting on spark master process :: ${_master_pid}"
  62. wait_external $_master_pid
  63. done