stop_graceful.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Licensed to the LF AI & Data foundation under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with 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. function get_milvus_process() {
  17. echo $(ps -e | grep milvus | grep -v grep | grep run-with-subprocess | awk '{print $1}')
  18. }
  19. echo "Stopping milvus..."
  20. BASEDIR=$(dirname "$0")
  21. timeout=120
  22. if [ ! -z "$1" ]; then
  23. timeout=$1
  24. fi
  25. if [ -z $(get_milvus_process) ]; then
  26. echo "No milvus process"
  27. exit 0
  28. fi
  29. kill -15 $(get_milvus_process)
  30. start=$(date +%s)
  31. while :
  32. do
  33. sleep 1
  34. if [ -z $(get_milvus_process) ]; then
  35. echo "Milvus stopped"
  36. break
  37. fi
  38. if [ $(( $(date +%s) - $start )) -gt $timeout ]; then
  39. echo "Milvus timeout stopped"
  40. kill -15 $(get_milvus_process)
  41. break
  42. fi
  43. done