set-ceph-debug-level 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/env bash
  2. # Copyright 2021 The Rook Authors. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -e
  16. if [ -z "$1" ]; then
  17. echo "no debug level passed choose between 0 and 20"
  18. exit 1
  19. fi
  20. CEPH_DEBUG_LEVEL=$1
  21. CEPH_DEBUG_FLAG=(
  22. lockdep
  23. context
  24. crush
  25. mds
  26. mds_balancer
  27. mds_locker
  28. mds_log
  29. mds_log_expire
  30. mds_migrator
  31. buffer
  32. timer
  33. filer
  34. striper
  35. objecter
  36. rados
  37. rbd
  38. rbd_mirror
  39. rbd_replay
  40. journaler
  41. objectcacher
  42. client
  43. osd
  44. optracker
  45. objclass
  46. ms
  47. mon
  48. monc
  49. paxos
  50. tp
  51. auth
  52. crypto
  53. finisher
  54. reserver
  55. heartbeatmap
  56. perfcounter
  57. rgw
  58. rgw_sync
  59. civetweb
  60. javaclient
  61. asok
  62. throttle
  63. refs
  64. compressor
  65. bluestore
  66. bluefs
  67. bdev
  68. kstore
  69. rocksdb
  70. leveldb
  71. memdb
  72. fuse
  73. mgr
  74. mgrc
  75. dpdk
  76. eventtrace
  77. )
  78. #############
  79. # FUNCTIONS #
  80. #############
  81. check() {
  82. ok_to_run=1
  83. if [[ "$CEPH_DEBUG_LEVEL" =~ ^[0-9]+$ ]]; then
  84. if [ "$CEPH_DEBUG_LEVEL" -ge 0 ] && [ "$CEPH_DEBUG_LEVEL" -le 20 ]; then
  85. ok_to_run=0
  86. fi
  87. elif [[ "$CEPH_DEBUG_LEVEL" == "default" ]]; then
  88. ok_to_run=0
  89. fi
  90. }
  91. exec_ceph_command() {
  92. local debug_level=$1
  93. local action=set
  94. if [[ "$debug_level" == "default" ]]; then
  95. action="rm"
  96. fi
  97. # exec command
  98. for flag in "${CEPH_DEBUG_FLAG[@]}"; do
  99. ARGS=("$action" global debug_"$flag")
  100. if [[ "$debug_level" != "default" ]]; then
  101. ARGS+=("$debug_level")
  102. fi
  103. # put stdout in /dev/null since increase debug log will overflow the terminal
  104. echo "ceph config ${ARGS[*]}"
  105. ceph config "${ARGS[@]}" &> /dev/null & pids+=($!)
  106. done
  107. echo "waiting for all the new logging configuration to be applied, this can take a few seconds"
  108. wait "${pids[@]}"
  109. }
  110. ########
  111. # MAIN #
  112. ########
  113. check
  114. if [ "$ok_to_run" -eq 0 ]; then
  115. exec_ceph_command "$CEPH_DEBUG_LEVEL"
  116. else
  117. echo "Wrong debug level $CEPH_DEBUG_LEVEL"
  118. echo "MUST be integer between 0 and 20 or 'default' to reset all values"
  119. exit 1
  120. fi