configmgr.in 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. # Common Function
  19. #------------------------------------------------------------------------------
  20. ###<REPLACE>###
  21. createConf ()
  22. {
  23. awk -f ${reg_path}/regex.awk -v NEW_ENVFILE=$1 -v NEW_PORT=$2 -v NEW_CONFFILE=$3< ${path}${configs}/configmgr/esp.xml >${runtime}/${compName}/esp.xml
  24. }
  25. removePidfiles ()
  26. {
  27. rm -rf ${runtime}/${compName}.pid
  28. rm -rf ${lock}/${compName}.lock
  29. rm -rf ${pid}/${compName}_init.pid
  30. rm -rf ${pid}/${compName}.pid
  31. rm -rf ${pid}/init_${compName}.pid
  32. }
  33. cleanup ()
  34. {
  35. echo "Exiting configMgr"
  36. #stop configesp
  37. PIDPATH=${pid}/${compName}_init.pid
  38. stopcmd="${START_STOP_DAEMON} -K -p $PIDPATH"
  39. eval $stopcmd
  40. sleep 2
  41. killall -9 configesp >/dev/null 2>&1
  42. removePidfiles
  43. exit
  44. }
  45. control_c ()
  46. {
  47. echo "Ctrl-c was hit. Exiting the process"
  48. cleanup
  49. exit
  50. }
  51. print_usage ()
  52. {
  53. echo >&2 "Usage : $0 <full path for env file> <port> <full path for conf file>
  54. or $0 (will use default files and default port number)"
  55. exit 0
  56. }
  57. source ${INSTALL_DIR}/etc/init.d/lock.sh
  58. source ${INSTALL_DIR}/etc/init.d/pid.sh
  59. source ${INSTALL_DIR}/etc/init.d/hpcc_common
  60. source ${INSTALL_DIR}/etc/init.d/init-functions
  61. source ${INSTALL_DIR}/etc/init.d/export-path
  62. HPCC_CONFIG=${HPCC_CONFIG:-${CONFIG_DIR}/${ENV_CONF_FILE}}
  63. SECTION=${SECTION:-DEFAULT}
  64. cfg.parser ${HPCC_CONFIG}
  65. cfg.section.${SECTION}
  66. if [ ${DEBUG:-NO_DEBUG} != "NO_DEBUG" ]; then
  67. echo "\$runtime=$runtime"
  68. echo "\$path=$path"
  69. echo "\$configs=$configs"
  70. echo "\$configsbackup=$configsbackup"
  71. echo "\$user=$user"
  72. echo "\$lock=$lock"
  73. echo "\$pid=$pid"
  74. echo "\$log=$log"
  75. echo "\$environment=$environment"
  76. echo "\$interface=$interface"
  77. echo "\$sourcedir=$sourcedir"
  78. echo
  79. fi
  80. exec_script_path=${path}/bin
  81. reg_path=${path}/sbin
  82. compName=configmgr
  83. is_root
  84. # Trapping keyboard interrupt control-c
  85. trap control_c SIGINT
  86. # Setting up Environment variables
  87. export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${path}/lib
  88. export PATH=${PATH}:${runtime}/bin:${path}/sbin
  89. # Creating runtime environment for ConfigMgr
  90. mkdir -p ${pid}
  91. chown -R ${user}:${group} ${pid}
  92. mkdir -p ${lock}
  93. chown -R ${user}:${group} ${lock}
  94. mkdir -p ${runtime}/$compName
  95. chown -R ${user}:${group} ${runtime}/$compName
  96. mkdir -p ${log}/$compName
  97. chown -R ${user}:${group} ${log}/$compName
  98. mkdir -p ${lock}/$compName
  99. chown -R ${user}:${group} ${lock}/$compName
  100. mkdir -p ${pid}/$compName
  101. chown -R ${user}:${group} ${pid}/$compName
  102. logFile=${log}/${compName}/${compName}.log
  103. initPidFile=${pid}/${compName}_init.pid
  104. compPidFile=${pid}/${compName}.pid
  105. lockFile=${lock}/${compName}.lock
  106. defaultEnv=0
  107. # Checking input arguments
  108. if [ $# -eq 3 ]; then
  109. filename=$1
  110. portnum=$2
  111. conffile=$3
  112. echo "<filename> = ${filename}"
  113. echo "<portnumber> = ${portnum}"
  114. echo "<LocalConfFile> = ${conffile}"
  115. #checking where files exists or not
  116. if [ ! -e ${filename} ] || [ ! -e ${conffile} ]
  117. then
  118. echo "File ${filename} or ${conffile} does not exists"
  119. exit
  120. fi
  121. elif [ $# -eq 0 ]; then
  122. defaultEnv=1
  123. filename="${sourcedir}/${environment}"
  124. portnum="8015"
  125. conffile="${configs}/environment.conf"
  126. echo "Using default filename ${sourcedir}/${environment} and default port \"8015\""
  127. if [ ! -d ${sourcedir} ];
  128. then
  129. #creating source directory if not present
  130. createDir ${sourcedir}
  131. cp ${configs}/${environment} ${sourcedir} > /dev/null 2<&1
  132. chmod 755 ${sourcedir}/${environment}
  133. chown -R ${user}:${group} ${sourcedir}
  134. else
  135. if [ ! -e ${filename} ];
  136. then
  137. if [ ${DEBUG:-NO_DEBUG} != "NO_DEBUG" ]; then
  138. echo "Default environment file does not exists, copying from ${configs}"
  139. fi
  140. cp ${configs}/${environment} ${sourcedir}/environment.xml > /dev/null 2<&1
  141. chmod 755 ${sourcedir}/environment.xml
  142. chown -R ${user}:${group} ${sourcedir}
  143. fi
  144. fi
  145. else
  146. print_usage
  147. fi
  148. createConf "${filename}" "${portnum}" "${conffile}"
  149. chown ${user}:${group} ${conffile}
  150. # Sanity Check for previous instances of configmgr. This code also takes care if configmgr script/configesp is not running and it killed by kill command
  151. check_status ${initPidFile} ${lockFile} ${compPidFile} 0
  152. RCSTAT=$?
  153. if [ ${RCSTAT} -eq 0 ]; then
  154. checkPid ${initPidFile}
  155. echo "Configmgr is already running with Pid $__pidValue"
  156. exit 0
  157. else
  158. #component is not running, If pid/lock file exist remove them
  159. if [ ${RCSTAT} -eq 1 ] || [ ${RCSTAT} -eq 2 ]
  160. then
  161. removePidfiles
  162. fi
  163. fi
  164. #-----------------------------------------------------------
  165. # Actual Processing begins
  166. #-----------------------------------------------------------
  167. cd ${runtime}/${compName}
  168. #start configesp
  169. EXEC_COMMAND="${exec_script_path}/init_configesp >> $logFile 2>&1"
  170. startcmd="${START_STOP_DAEMON} -S -p ${initPidFile} -c ${user}:${group} -d ${runtime}/${compName} -m -x ${EXEC_COMMAND} -b"
  171. eval ${startcmd}
  172. started=$?
  173. if [ ${DEBUG:-NO_DEBUG} != "NO_DEBUG" ]; then
  174. echo $startcmd
  175. echo "configesp status = $started"
  176. fi
  177. echo -n "Verifying configmgr startup ..."
  178. sleep 2
  179. check_status ${initPidFile} ${lockFile} ${compPidFile} 1
  180. RCSTAT=$?
  181. if [ ${RCSTAT} -ne 0 ];then
  182. echo "Failure"
  183. cleanup
  184. else
  185. echo " Success"
  186. echo "Exit by pressing ctrl-c..."
  187. while :
  188. check_status ${initPidFile} ${lockFile} ${compPidFile} 1
  189. if [ $? -ne 0 ] ;
  190. then
  191. if [ "${DEBUG}" != "NO_DEBUG" ];
  192. then
  193. echo "Init_configesp/Configesp is not running, hence shutting down configmgr script"
  194. fi
  195. kill -2 $$ > /dev/null 2>&1
  196. fi
  197. trap control_c SIGINT
  198. do
  199. sleep 1
  200. done
  201. fi