configmgr.in 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. DEBUG=${DEBUG:-NO_DEBUG}
  22. source ${INSTALL_DIR}/etc/init.d/hpcc_common
  23. createConf ()
  24. {
  25. dir_name=$(basename ${INSTALL_DIR})
  26. awk -f ${reg_path}/regex.awk -v NEW_ENVFILE=$1 -v NEW_PORT=$2 -v NEW_CONFFILE=$3< ${path}/etc/${dir_name}/configmgr/esp.xml >${runtime}/${compName}/esp.xml
  27. }
  28. cleanup ()
  29. {
  30. echo "Exiting configMgr"
  31. PIDPATH=${pid}/${compName}_init.pid
  32. stopcmd="${START_STOP_DAEMON} -K -p $PIDPATH"
  33. eval $stopcmd
  34. sleep 2
  35. cleanupRuntimeEnvironment
  36. exit
  37. }
  38. control_c ()
  39. {
  40. echo "Ctrl-c was hit. Exiting the process"
  41. cleanup
  42. exit
  43. }
  44. print_usage ()
  45. {
  46. echo >&2 "Usage : $0 <full path for env file> <port> <full path for conf file>
  47. or $0 (will use default files and default port number)"
  48. exit 0
  49. }
  50. set_environmentvars
  51. exec_script_path=${path}/bin
  52. reg_path=${path}/sbin
  53. compName=configmgr
  54. compPath=${runtime}/${compName}
  55. [[ ! -w "${CONFIG_DIR}" ]] && is_root
  56. # Trapping keyboard interrupt control-c
  57. trap control_c SIGINT
  58. # Setting up Environment variables
  59. export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${path}/lib
  60. export PATH=${PATH}:${runtime}/bin:${path}/sbin
  61. # Creating runtime environment for ConfigMgr
  62. createRuntime
  63. logFile=${log}/${compName}/${compName}.log
  64. initPidFile=${pid}/${compName}_init.pid
  65. compPidFile=${pid}/${compName}.pid
  66. lockFile=${lock}/${compName}/${compName}.lock
  67. defaultEnv=0
  68. # Checking input arguments
  69. if [ $# -eq 3 ]; then
  70. filename=$1
  71. portnum=$2
  72. conffile=$3
  73. echo "<filename> = ${filename}"
  74. echo "<portnumber> = ${portnum}"
  75. echo "<LocalEnvConfFile> = ${conffile}"
  76. #checking where files exists or not
  77. if [ ! -e ${filename} ] || [ ! -e ${conffile} ]
  78. then
  79. echo "File ${filename} or ${conffile} does not exists"
  80. exit
  81. fi
  82. elif [ $# -eq 0 ]; then
  83. defaultEnv=1
  84. filename="${sourcedir}/${environment}"
  85. portnum="8015"
  86. conffile="${configs}/environment.conf"
  87. echo "Using default filename ${sourcedir}/${environment} and default port \"8015\""
  88. if [ ! -d ${sourcedir} ];
  89. then
  90. #creating source directory if not present
  91. createDir ${sourcedir}
  92. cp ${configs}/${environment} ${sourcedir} > /dev/null 2<&1
  93. chmod 755 ${sourcedir}/${environment}
  94. chown -R ${user}:${group} ${sourcedir}
  95. else
  96. if [ ! -e ${filename} ];
  97. then
  98. if [ ${DEBUG:-NO_DEBUG} != "NO_DEBUG" ]; then
  99. echo "Default environment file does not exists, copying from ${configs}"
  100. fi
  101. cp ${configs}/${environment} ${sourcedir}/environment.xml > /dev/null 2<&1
  102. chmod 755 ${sourcedir}/environment.xml
  103. chown -R ${user}:${group} ${sourcedir}
  104. fi
  105. fi
  106. else
  107. print_usage
  108. fi
  109. createConf "${filename}" "${portnum}" "${conffile}"
  110. chown ${user}:${group} ${conffile}
  111. # 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
  112. check_status ${initPidFile} ${lockFile} ${compPidFile} 0
  113. RCSTAT=$?
  114. if [ ${RCSTAT} -eq 0 ]; then
  115. checkPid ${initPidFile}
  116. echo "Configmgr is already running with Pid $__pidValue"
  117. exit 0
  118. else
  119. cleanupRuntimeEnvironment
  120. fi
  121. #-----------------------------------------------------------
  122. # Actual Processing begins
  123. #-----------------------------------------------------------
  124. cd ${runtime}/${compName}
  125. #start configesp
  126. EXEC_COMMAND="${exec_script_path}/init_configesp >> $logFile 2>&1"
  127. startcmd="${START_STOP_DAEMON} -S -p ${initPidFile} -c ${user}:${group} -d ${runtime}/${compName} -m -x ${EXEC_COMMAND} -b"
  128. eval ${startcmd}
  129. started=$?
  130. # Creating a Lock
  131. lock $lockFile
  132. if [ ${DEBUG:-NO_DEBUG} != "NO_DEBUG" ]; then
  133. echo $startcmd
  134. echo "configesp status = $started"
  135. fi
  136. echo -n "Verifying configmgr startup ..."
  137. sleep 2
  138. check_status ${initPidFile} ${lockFile} ${compPidFile} 1
  139. RCSTAT=$?
  140. if [ ${RCSTAT} -ne 0 ];then
  141. echo "Failure"
  142. cleanup
  143. else
  144. echo " Success"
  145. echo "Exit by pressing ctrl-c..."
  146. while :
  147. check_status ${initPidFile} ${lockFile} ${compPidFile} 1
  148. if [ $? -ne 0 ] ;
  149. then
  150. if [ "${DEBUG}" != "NO_DEBUG" ];
  151. then
  152. echo "Init_configesp/Configesp is not running, hence shutting down configmgr script"
  153. fi
  154. kill -2 $$ > /dev/null 2>&1
  155. fi
  156. trap control_c SIGINT
  157. do
  158. sleep 1
  159. done
  160. fi