influxdb-restart.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env bash
  2. #
  3. # The MIT License
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in
  13. # all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. # THE SOFTWARE.
  22. #
  23. set -e
  24. DEFAULT_INFLUXDB_VERSION="1.8.3"
  25. INFLUXDB_VERSION="${INFLUXDB_VERSION:-$DEFAULT_INFLUXDB_VERSION}"
  26. INFLUXDB_IMAGE=influxdb:${INFLUXDB_VERSION}-alpine
  27. DEFAULT_INFLUXDB_V2_VERSION="latest"
  28. INFLUXDB_V2_VERSION="${INFLUXDB_V2_VERSION:-$DEFAULT_INFLUXDB_V2_VERSION}"
  29. INFLUXDB_V2_IMAGE=influxdb:${INFLUXDB_V2_VERSION}
  30. SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
  31. docker kill influxdb || true
  32. docker rm influxdb || true
  33. docker kill influxdb_v2 || true
  34. docker rm influxdb_v2 || true
  35. docker kill influxdb_v2_onboarding || true
  36. docker rm influxdb_v2_onboarding || true
  37. docker network rm influx_network || true
  38. docker network create -d bridge influx_network --subnet 192.168.0.0/24 --gateway 192.168.0.1
  39. echo
  40. echo "Restarting InfluxDB [${INFLUXDB_IMAGE}] ..."
  41. echo
  42. #
  43. # InfluxDB 1.8
  44. #
  45. docker pull ${INFLUXDB_IMAGE} || true
  46. docker run \
  47. --detach \
  48. --name influxdb \
  49. --network influx_network \
  50. --publish 8087:8086 \
  51. --volume ${SCRIPT_PATH}/influxdb.conf:/etc/influxdb/influxdb.conf \
  52. ${INFLUXDB_IMAGE}
  53. echo "Wait to start InfluxDB"
  54. wget -S --spider --tries=20 --retry-connrefused --waitretry=5 http://localhost:8087/ping
  55. echo
  56. echo "Post with create dabase"
  57. echo
  58. curl -X POST localhost:8087/query --data-urlencode "q=create database mydb"
  59. #
  60. # InfluxDB 2.0
  61. #
  62. echo
  63. echo "Restarting InfluxDB 2.0 [${INFLUXDB_V2_IMAGE}] ... "
  64. echo
  65. docker pull ${INFLUXDB_V2_IMAGE} || true
  66. docker run \
  67. --detach \
  68. --name influxdb_v2 \
  69. --network influx_network \
  70. --publish 8086:8086 \
  71. ${INFLUXDB_V2_IMAGE}
  72. echo "Wait to start InfluxDB 2.0"
  73. wget -S --spider --tries=20 --retry-connrefused --waitretry=5 http://localhost:8086/metrics
  74. echo
  75. echo "Post onBoarding request, to setup initial user (my-user@my-password), org (my-org) and bucketSetup (my-bucket)"
  76. echo
  77. curl -i -X POST http://localhost:8086/api/v2/setup -H 'accept: application/json' \
  78. -d '{
  79. "username": "my-user",
  80. "password": "my-password",
  81. "org": "my-org",
  82. "bucket": "my-bucket",
  83. "token": "my-token"
  84. }'
  85. #
  86. # InfluxDB 2.0
  87. #
  88. echo
  89. echo "Restarting InfluxDB 2.0 for onboarding test... "
  90. echo
  91. docker run \
  92. --detach \
  93. --name influxdb_v2_onboarding \
  94. --network influx_network \
  95. --publish 8089:8086 \
  96. ${INFLUXDB_V2_IMAGE}