S99fluent-bit 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh
  2. DAEMON="fluent-bit"
  3. PID_FILE="/var/run/$DAEMON.pid"
  4. CONF_FILE="/etc/$DAEMON/$DAEMON.conf"
  5. FLUENT_BIT_ARGS=""
  6. # shellcheck source=/dev/null
  7. [ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
  8. start() {
  9. printf 'Starting %s: ' "$DAEMON"
  10. # shellcheck disable=SC2086 # we need the word splitting
  11. start-stop-daemon -S -q -b -m -p "$PID_FILE" --exec "/usr/bin/$DAEMON" \
  12. -- -c "$CONF_FILE" $FLUENT_BIT_ARGS
  13. status=$?
  14. if [ "$status" -eq 0 ]; then
  15. echo "OK"
  16. else
  17. echo "FAIL"
  18. fi
  19. return "$status"
  20. }
  21. stop() {
  22. printf 'Stopping %s: ' "$DAEMON"
  23. start-stop-daemon -K -q -p "$PID_FILE"
  24. status=$?
  25. if [ -f "$PID_FILE" ]; then
  26. pid=$(cat "$PID_FILE")
  27. rm -f "$PID_FILE"
  28. # https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/yaml/configuration-file#config_section
  29. # The default grace time is set to 5 seconds, so use 6 seconds to have some margin.
  30. timeout=6
  31. while kill -0 "$pid" 2>/dev/null; do
  32. [ $timeout -eq 0 ] && status=1 && break
  33. timeout=$((timeout - 1))
  34. sleep 1
  35. done
  36. fi
  37. if [ "$status" -eq 0 ]; then
  38. echo "OK"
  39. else
  40. echo "FAIL"
  41. fi
  42. return "$status"
  43. }
  44. restart() {
  45. stop
  46. start
  47. }
  48. case "$1" in
  49. start)
  50. start
  51. ;;
  52. stop)
  53. stop
  54. ;;
  55. restart | reload)
  56. restart
  57. ;;
  58. *)
  59. echo "Usage: $0 {start|stop|restart}"
  60. exit 1
  61. ;;
  62. esac