bsd-init.in 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh
  2. # Start/stop/restart/reload nrpe
  3. # Copyright (c) 2016 Nagios(R) Core(TM) Development Team
  4. NRPE_BIN=@sbindir@/nrpe
  5. NRPE_CFG=@pkgsysconfdir@/nrpe.cfg
  6. PID_DIR=@piddir@
  7. PID_FILE=@piddir@/nrpe.pid
  8. # Start nrpe
  9. nrpe_start() {
  10. echo -n "Starting nrpe daemon: $NRPE_BIN - "
  11. if [ ! -d "$PID_DIR" ]; then
  12. mkdir -p "$PID_DIR"
  13. fi
  14. $NRPE_BIN -c $NRPE_CFG -d
  15. if [ $? = 0 ]; then
  16. echo "started"
  17. else
  18. echo "failed"
  19. fi
  20. }
  21. # Stop nrpe
  22. nrpe_stop() {
  23. echo -n "Stopping nrpe daemon - "
  24. if [ -r "$PID_FILE" ]; then
  25. kill $(cat "$PID_FILE")
  26. else
  27. killall nrpe
  28. fi
  29. if [ $? = 0 ]; then
  30. echo "stopped"
  31. else
  32. echo "failed"
  33. fi
  34. }
  35. # Restart nrpe
  36. nrpe_restart() {
  37. nrpe_stop
  38. sleep 1
  39. nrpe_start
  40. }
  41. # Reload nrpe
  42. nrpe_reload() {
  43. echo -n "Reloading nrpe daemon - "
  44. if [ -r "$PID_FILE" ]; then
  45. kill -HUP $(cat "$PID_FILE")
  46. else
  47. killall -HUP nrpe
  48. fi
  49. if [ $? = 0 ]; then
  50. echo "reloaded"
  51. else
  52. echo "failed"
  53. fi
  54. }
  55. # nrpe status
  56. nrpe_status() {
  57. if ps -C nrpe >/dev/null; then
  58. echo "nrpe is running."
  59. else
  60. echo "nrpe is stopped."
  61. fi
  62. }
  63. case "$1" in
  64. 'start')
  65. nrpe_start
  66. ;;
  67. 'stop')
  68. nrpe_stop
  69. ;;
  70. 'restart')
  71. nrpe_restart
  72. ;;
  73. 'reload')
  74. nrpe_reload
  75. ;;
  76. 'status')
  77. nrpe_status
  78. ;;
  79. *)
  80. echo "Usage $0 start|stop|restart|reload|status"
  81. ;;
  82. esac