entrypoint.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env sh
  2. set -e
  3. hosts()
  4. {
  5. host="/etc/hosts.main"
  6. yes="/etc/hosts.yes"
  7. if [ ! -s "$yes" ]; then
  8. if [ -s "$host" ]; then
  9. while read line
  10. do
  11. echo $line >> /etc/hosts
  12. done < $host
  13. echo "yes" > $yes
  14. fi
  15. fi
  16. }
  17. process()
  18. {
  19. echo "$1 Startup Completed" > /share/process/$1
  20. }
  21. check()
  22. {
  23. path="process"
  24. if [ -n "$2" ];then
  25. path="$2"
  26. fi
  27. process="/share/$path/$1"
  28. while [ ! -s "$process" ]; do
  29. true
  30. done
  31. }
  32. share()
  33. {
  34. path=/share/lib/$2
  35. if [ ! -d "$path" ]; then
  36. mkdir -p "$path"
  37. fi
  38. cp -R $1/* $path
  39. }
  40. hadoop_mkdir()
  41. {
  42. dir=$(hadoop fs -ls / | grep $1 | wc -l)
  43. if [ $dir -eq 0 ] ;then
  44. for i in $@
  45. do
  46. hadoop fs -mkdir -p /$i
  47. done
  48. fi
  49. }
  50. load()
  51. {
  52. dir=/entrypoint/
  53. loop=$(ls -l $dir |awk '{print $9}')
  54. for i in $loop
  55. do
  56. source $dir$i
  57. done
  58. }
  59. start()
  60. {
  61. if [ -n "$1" ];then
  62. start="start_$@"
  63. echo "$start"
  64. status=`$start`
  65. echo $status
  66. netstat -apn
  67. process $1
  68. fi
  69. }
  70. stop()
  71. {
  72. if [ -n "$1" ];then
  73. stop="stop_$@"
  74. echo "$stop"
  75. status=`$stop`
  76. echo $status
  77. rm -rf /share/process/$1
  78. fi
  79. }
  80. monit()
  81. {
  82. if [ -n "$1" ];then
  83. monit="monit_$@"
  84. status=`$monit`
  85. fi
  86. }
  87. load
  88. hosts
  89. start $@
  90. if [ "$2" == "exit" ]; then
  91. exit 0
  92. fi
  93. trap "stop $1" HUP INT QUIT ABRT KILL ALRM TERM EXIT
  94. while true
  95. do
  96. monit $@
  97. sleep 10
  98. done
  99. #exec sh
  100. exit 0