dafilesrv.in 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/bin/bash
  2. ################################################################################
  3. # HPCC SYSTEMS software Copyright (C) 2012 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. #
  18. #
  19. #########################################################################
  20. # #
  21. # System Flow #
  22. # #
  23. #########################################################################
  24. # #
  25. # 1. Parse Passed In arguments #
  26. # 2. Get the component and specific information #
  27. # 3. Generate component related config files (runtime directory) #
  28. # 4. CD to the runtime Directory #
  29. # 5. Start the component #
  30. # #
  31. #########################################################################
  32. ##-----------------------------------------------------------------------------
  33. # chkconfig Parameters
  34. ##-----------------------------------------------------------------------------
  35. ### BEGIN INIT INFO
  36. # chkconfig: 235 30 80
  37. # Description: Starts the HPCC dafilesrv processes
  38. # Short-Description: Controls HPCC dafilesrv
  39. # Provides: dafilesrv
  40. # Required-Start:
  41. # Required-Stop:
  42. # Default-Start:
  43. # Default-Stop:
  44. ### END INIT INFO
  45. ##-----------------------------------------------------------------------------
  46. # General Purpose Functions
  47. ##-----------------------------------------------------------------------------
  48. ###<REPLACE>###
  49. function print_usage {
  50. echo >&2 "Usage: $0 {start|stop|restart|status|setup}
  51. $0 [-h] [--help]"
  52. exit 0
  53. }
  54. cfggenpre=()
  55. source ${INSTALL_DIR}/etc/init.d/lock.sh
  56. source ${INSTALL_DIR}/etc/init.d/pid.sh
  57. source ${INSTALL_DIR}/etc/init.d/hpcc_common
  58. source ${INSTALL_DIR}/etc/init.d/init-functions
  59. source ${INSTALL_DIR}/etc/init.d/export-path
  60. ## Debug variable allowing verbose debug output
  61. ##
  62. DEBUG=${DEBUG:-NO_DEBUG}
  63. TRACE=${TRACE:-0}
  64. VERBOSE=${VERBOSE:-0}
  65. configgen_path=${INSTALL_DIR}/sbin
  66. basepath=`pwd`
  67. set_environmentvars
  68. envfile=$configs/$environment
  69. bin_path=${INSTALL_DIR}/bin
  70. component=""
  71. runSetupOnly=0
  72. source ${configgen_path}/hpcc_setenv
  73. createDir ${LOG_DIR}
  74. which_service
  75. #Check for existance of user
  76. check_user ${user}
  77. if [ $? -ne 1 ];then
  78. echo "User ${user} does not exist on the system. Exiting ..."
  79. exit 3
  80. fi
  81. check_group ${group}
  82. if [ $? -ne 1 ];then
  83. echo "Group ${group} does not exist on the system or not able to chgrp (sudo?). Exiting ..."
  84. exit 3
  85. fi
  86. check_getopt
  87. COMPS=$(${configgen_path}/configgen -env ${envfile} -ip "127.0.0.1" -list)
  88. rc=$?
  89. if [[ $rc -ne 0 ]]; then
  90. log "hpcc-init: failure to build COMPS from configgen call"
  91. echo -e "\033[31merror\033[0m: hpcc-init -> failure to build COMPS from configgen call"
  92. exit 1
  93. fi
  94. comp.parser ${COMPS}
  95. for i in ${compArray[@]}; do
  96. compName=${i#*_}
  97. comp.getByName ${compName}
  98. compType=`echo $comp_return | cut -d ' ' -f 1 | cut -d '=' -f 2 `
  99. if strstr ${compType} "dafilesrv" ;
  100. then
  101. component=${compName}
  102. break
  103. fi
  104. done
  105. ##################################################################################
  106. # Beginning of the Option Parsing #
  107. ##################################################################################
  108. if [ -z "${component}" ] ; then
  109. log_failure_msg "dafilesrv is not configured to run on this node"
  110. exit 3
  111. fi
  112. TEMP=`getopt -o h --long help -n 'dafilesrv' -- "$@"`
  113. if [ $? != 0 ] ; then echo "Failure to parse commandline." >&2 ; exit 1 ; fi
  114. eval set -- $TEMP
  115. while true ; do
  116. case "$1" in
  117. -h|--help) print_usage
  118. shift ;;
  119. --) shift ; break ;;
  120. *) print_usage ;;
  121. esac
  122. done
  123. for arg do arg=$arg; done
  124. if [ -z "$arg" ] || [ $# -ne 1 ]; then
  125. print_usage
  126. fi
  127. # for starting hpcc components concurrently, as
  128. # configgen -validateonly does not create unique tempdirs
  129. thisos=$(uname -s)
  130. if [[ "$thisos" = "Linux" && -f "${envfile}" && -n "${component}" && \
  131. "${DEBUG}" = "NO_DEBUG" && -z "$HPCC_NO_FLOCK" ]] ; then
  132. cfggenpre=(flock ${envfile})
  133. fi
  134. case "$arg" in
  135. status|start|restart|stop|setup)
  136. cmd=$arg
  137. ;;
  138. *) print_usage
  139. ;;
  140. esac
  141. if [ "${cmd}" = "start" ] || [ "${cmd}" = "restart" ]; then
  142. validate_configuration
  143. fi
  144. unset IFS
  145. DAFS_LOCK="/tmp/dafs_lock"
  146. trap "rm -f $DAFS_LOCK" SIGINT SIGTERM SIGQUIT
  147. STATUS=0
  148. for C in ${component} ; do
  149. set_componentvars ${C}
  150. if [ "${cmd}" == "start" ];then
  151. xcmd="${cmd}_dafilesrv ${C}"
  152. else
  153. xcmd="${cmd}_component ${C}"
  154. fi
  155. if [ ${DEBUG} != "NO_DEBUG" ]; then
  156. echo $xcmd
  157. fi
  158. if [[ "${cmd}" == "start" && "${thisos}" == "Linux" ]]; then
  159. (
  160. flock 99
  161. eval $xcmd
  162. STATUS=$?
  163. rm -f $DAFS_LOCK
  164. ) 99>$DAFS_LOCK
  165. else
  166. eval $xcmd
  167. STATUS=$?
  168. fi
  169. done
  170. exit ${STATUS}