standalone_embed.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/usr/bin/env bash
  2. # Licensed to the LF AI & Data foundation 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. run_embed() {
  18. cat << EOF > embedEtcd.yaml
  19. listen-client-urls: http://0.0.0.0:2379
  20. advertise-client-urls: http://0.0.0.0:2379
  21. quota-backend-bytes: 4294967296
  22. auto-compaction-mode: revision
  23. auto-compaction-retention: '1000'
  24. EOF
  25. cat << EOF > user.yaml
  26. # Extra config to override default milvus.yaml
  27. EOF
  28. sudo docker run -d \
  29. --name milvus-standalone \
  30. --security-opt seccomp:unconfined \
  31. -e ETCD_USE_EMBED=true \
  32. -e ETCD_DATA_DIR=/var/lib/milvus/etcd \
  33. -e ETCD_CONFIG_PATH=/milvus/configs/embedEtcd.yaml \
  34. -e COMMON_STORAGETYPE=local \
  35. -v $(pwd)/volumes/milvus:/var/lib/milvus \
  36. -v $(pwd)/embedEtcd.yaml:/milvus/configs/embedEtcd.yaml \
  37. -v $(pwd)/user.yaml:/milvus/configs/user.yaml \
  38. -p 19530:19530 \
  39. -p 9091:9091 \
  40. -p 2379:2379 \
  41. --health-cmd="curl -f http://localhost:9091/healthz" \
  42. --health-interval=30s \
  43. --health-start-period=90s \
  44. --health-timeout=20s \
  45. --health-retries=3 \
  46. milvusdb/milvus:v2.4.13-hotfix \
  47. milvus run standalone 1> /dev/null
  48. }
  49. wait_for_milvus_running() {
  50. echo "Wait for Milvus Starting..."
  51. while true
  52. do
  53. res=`sudo docker ps|grep milvus-standalone|grep healthy|wc -l`
  54. if [ $res -eq 1 ]
  55. then
  56. echo "Start successfully."
  57. echo "To change the default Milvus configuration, add your settings to the user.yaml file and then restart the service."
  58. break
  59. fi
  60. sleep 1
  61. done
  62. }
  63. start() {
  64. res=`sudo docker ps|grep milvus-standalone|grep healthy|wc -l`
  65. if [ $res -eq 1 ]
  66. then
  67. echo "Milvus is running."
  68. exit 0
  69. fi
  70. res=`sudo docker ps -a|grep milvus-standalone|wc -l`
  71. if [ $res -eq 1 ]
  72. then
  73. sudo docker start milvus-standalone 1> /dev/null
  74. else
  75. run_embed
  76. fi
  77. if [ $? -ne 0 ]
  78. then
  79. echo "Start failed."
  80. exit 1
  81. fi
  82. wait_for_milvus_running
  83. }
  84. stop() {
  85. sudo docker stop milvus-standalone 1> /dev/null
  86. if [ $? -ne 0 ]
  87. then
  88. echo "Stop failed."
  89. exit 1
  90. fi
  91. echo "Stop successfully."
  92. }
  93. delete_container() {
  94. res=`sudo docker ps|grep milvus-standalone|wc -l`
  95. if [ $res -eq 1 ]
  96. then
  97. echo "Please stop Milvus service before delete."
  98. exit 1
  99. fi
  100. sudo docker rm milvus-standalone 1> /dev/null
  101. if [ $? -ne 0 ]
  102. then
  103. echo "Delete milvus container failed."
  104. exit 1
  105. fi
  106. echo "Delete milvus container successfully."
  107. }
  108. delete() {
  109. delete_container
  110. sudo rm -rf $(pwd)/volumes
  111. sudo rm -rf $(pwd)/embedEtcd.yaml
  112. sudo rm -rf $(pwd)/user.yaml
  113. echo "Delete successfully."
  114. }
  115. upgrade() {
  116. read -p "Please confirm if you'd like to proceed with the upgrade. The default will be to the latest version. Confirm with 'y' for yes or 'n' for no. > " check
  117. if [ "$check" == "y" ] ||[ "$check" == "Y" ];then
  118. res=`sudo docker ps -a|grep milvus-standalone|wc -l`
  119. if [ $res -eq 1 ]
  120. then
  121. stop
  122. delete_container
  123. fi
  124. curl -sfL https://raw.githubusercontent.com/milvus-io/milvus/master/scripts/standalone_embed.sh -o standalone_embed_latest.sh && \
  125. bash standalone_embed_latest.sh start 1> /dev/null && \
  126. echo "Upgrade successfully."
  127. else
  128. echo "Exit upgrade"
  129. exit 0
  130. fi
  131. }
  132. case $1 in
  133. restart)
  134. stop
  135. start
  136. ;;
  137. start)
  138. start
  139. ;;
  140. stop)
  141. stop
  142. ;;
  143. upgrade)
  144. upgrade
  145. ;;
  146. delete)
  147. delete
  148. ;;
  149. *)
  150. echo "please use bash standalone_embed.sh restart|start|stop|upgrade|delete"
  151. ;;
  152. esac