logsearch-docker.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. 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. sdir="`dirname \"$0\"`"
  17. : ${1:?"argument is missing: (start|stop|build-and-run|build|build-docker-and-run|build-mvn-and-run|build-docker-only|build-mvn-only)"}
  18. command="$1"
  19. function build_logsearch_project() {
  20. pushd $sdir/../
  21. mvn clean package -DskipTests
  22. popd
  23. }
  24. function build_logsearch_container() {
  25. pushd $sdir
  26. docker build -t ambari-logsearch:v1.0 .
  27. popd
  28. }
  29. function start_logsearch_container() {
  30. setup_profile
  31. source $sdir/Profile
  32. : ${AMBARI_LOCATION:?"Please set the AMBARI_LOCATION in Profile"}
  33. : ${MAVEN_REPOSITORY_LOCATION:?"Please set the MAVEN_REPOSITORY_LOCATION in Profile"}
  34. kill_logsearch_container
  35. echo "Run Log Search container"
  36. docker run -d --name logsearch --hostname logsearch.apache.org \
  37. -v $AMBARI_LOCATION:/root/ambari -v $MAVEN_REPOSITORY_LOCATION:/root/.m2 $LOGSEARCH_EXPOSED_PORTS $LOGSEARCH_ENV_OPTS $LOGSEARCH_EXTRA_OPTS $LOGSEARCH_VOLUME_OPTS \
  38. -v $AMBARI_LOCATION/ambari-logsearch/ambari-logsearch-logfeeder/target/classes:/root/ambari/ambari-logsearch/ambari-logsearch-logfeeder/target/package/classes \
  39. -v $AMBARI_LOCATION/ambari-logsearch/ambari-logsearch-portal/target/classes:/root/ambari/ambari-logsearch/ambari-logsearch-portal/target/package/classes \
  40. -v $AMBARI_LOCATION/ambari-logsearch/ambari-logsearch-portal/src/main/webapp:/root/ambari/ambari-logsearch/ambari-logsearch-portal/target/package/classes/webapps/app ambari-logsearch:v1.0
  41. ip_address=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' logsearch)
  42. echo "Log Search container started on $ip_address (for Mac OSX route to boot2docker/docker-machine VM address, e.g.: 'sudo route add -net 172.17.0.0/16 192.168.59.103')"
  43. echo "You can follow Log Search logs with 'docker logs -f logsearch' command"
  44. }
  45. function setup_profile() {
  46. if [ -f "$sdir/Profile" ];
  47. then
  48. echo "Profile file exists"
  49. else
  50. echo "Profile does not exist, Creating a new one..."
  51. cat << EOF > $sdir/Profile
  52. AMBARI_LOCATION=$HOME/prj/ambari
  53. MAVEN_REPOSITORY_LOCATION=$HOME/.m2
  54. LOGSEARCH_EXPOSED_PORTS="-p 8886:8886 -p 61888:61888 -p 5005:5005 -p 5006:5006"
  55. LOGSEARCH_ENV_OPTS="-e LOGFEEDER_DEBUG_SUSPEND=n -e LOGSEARCH_DEBUG_SUSPEND=n -e COMPONENT_LOG=logsearch -e LOGSEARCH_HTTPS_ENABLED=false -e LOGSEARCH_SOLR_SSL_ENABLED=false"
  56. LOGSEARCH_VOLUME_OPTS="-v $AMBARI_LOCATION/ambari-logsearch/docker/test-logs:/root/test-logs -v $AMBARI_LOCATION/ambari-logsearch/docker/test-config:/root/test-config"
  57. LOGSEARCH_EXTRA_OPTS=""
  58. EOF
  59. echo "Profile has been created. Check it out before starting Log Search. ($sdir/Profile)"
  60. exit
  61. fi;
  62. }
  63. function kill_logsearch_container() {
  64. echo "Try to remove logsearch container if exists..."
  65. docker rm -f logsearch
  66. }
  67. case $command in
  68. "build-and-run")
  69. build_logsearch_project
  70. build_logsearch_container
  71. start_logsearch_container
  72. ;;
  73. "build")
  74. build_logsearch_project
  75. build_logsearch_container
  76. ;;
  77. "build-docker-and-run")
  78. build_logsearch_container
  79. start_logsearch_container
  80. ;;
  81. "build-mvn-and-run")
  82. build_logsearch_project
  83. start_logsearch_container
  84. ;;
  85. "build-docker-only")
  86. build_logsearch_container
  87. ;;
  88. "build-mvn-only")
  89. build_logsearch_project
  90. ;;
  91. "start")
  92. start_logsearch_container
  93. ;;
  94. "stop")
  95. kill_logsearch_container
  96. ;;
  97. *)
  98. echo "Available commands: (start|stop|build-and-run|build|build-docker-and-run|build-mvn-and-run|build-docker-only|build-mvn-only)"
  99. ;;
  100. esac