hadoop_env_checks.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. # -------------------------------------------------------
  18. function showWelcome {
  19. cat <<Welcome-message
  20. _ _ _ ______
  21. | | | | | | | _ \\
  22. | |_| | __ _ __| | ___ ___ _ __ | | | |_____ __
  23. | _ |/ _\` |/ _\` |/ _ \\ / _ \\| '_ \\ | | | / _ \\ \\ / /
  24. | | | | (_| | (_| | (_) | (_) | |_) | | |/ / __/\\ V /
  25. \\_| |_/\\__,_|\\__,_|\\___/ \\___/| .__/ |___/ \\___| \\_(_)
  26. | |
  27. |_|
  28. This is the standard Hadoop Developer build environment.
  29. This has all the right tools installed required to build
  30. Hadoop from source.
  31. Welcome-message
  32. }
  33. # -------------------------------------------------------
  34. function showAbort {
  35. cat <<Abort-message
  36. ___ _ _ _
  37. / _ \\| | | | (_)
  38. / /_\\ \\ |__ ___ _ __| |_ _ _ __ __ _
  39. | _ | '_ \\ / _ \\| '__| __| | '_ \\ / _\` |
  40. | | | | |_) | (_) | | | |_| | | | | (_| |
  41. \\_| |_/_.__/ \\___/|_| \\__|_|_| |_|\\__, |
  42. __/ |
  43. |___/
  44. Abort-message
  45. }
  46. # -------------------------------------------------------
  47. function failIfUserIsRoot {
  48. if [ "$(id -u)" -eq "0" ]; # If you are root then something went wrong.
  49. then
  50. cat <<End-of-message
  51. Apparently you are inside this docker container as the user root.
  52. Putting it simply:
  53. This should not occur.
  54. Known possible causes of this are:
  55. 1) Running this script as the root user ( Just don't )
  56. 2) Running an old docker version ( upgrade to 1.4.1 or higher )
  57. End-of-message
  58. showAbort
  59. logout
  60. fi
  61. }
  62. # -------------------------------------------------------
  63. # Configurable low water mark in GiB
  64. MINIMAL_MEMORY_GiB=2
  65. function warnIfLowMemory {
  66. MINIMAL_MEMORY=$((MINIMAL_MEMORY_GiB*1024*1024)) # Convert to KiB
  67. INSTALLED_MEMORY=$(fgrep MemTotal /proc/meminfo | awk '{print $2}')
  68. if [ $((INSTALLED_MEMORY)) -le $((MINIMAL_MEMORY)) ];
  69. then
  70. cat <<End-of-message
  71. _ ___ ___
  72. | | | \\/ |
  73. | | _____ __ | . . | ___ _ __ ___ ___ _ __ _ _
  74. | | / _ \\ \\ /\\ / / | |\\/| |/ _ \\ '_ \` _ \\ / _ \\| '__| | | |
  75. | |___| (_) \\ V V / | | | | __/ | | | | | (_) | | | |_| |
  76. \\_____/\\___/ \\_/\\_/ \\_| |_/\\___|_| |_| |_|\\___/|_| \\__, |
  77. __/ |
  78. |___/
  79. Your system is running on very little memory.
  80. This means it may work but it wil most likely be slower than needed.
  81. If you are running this via boot2docker you can simply increase
  82. the available memory to atleast ${MINIMAL_MEMORY_GiB} GiB (you have $((INSTALLED_MEMORY/(1024*1024))) GiB )
  83. End-of-message
  84. fi
  85. }
  86. # -------------------------------------------------------
  87. showWelcome
  88. warnIfLowMemory
  89. failIfUserIsRoot
  90. # -------------------------------------------------------