default-init.in 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2016 Nagios(R) Core(TM) Development Team
  4. #
  5. # chkconfig: - 80 30
  6. # description: Starts and stops the Nagios Remote Plugin Executor \
  7. # so a remote nagios server can run plugins on this host
  8. #
  9. ### BEGIN INIT INFO
  10. # Provides: nrpe
  11. # Required-Start: $local_fs $remote_fs $syslog $network $time
  12. # Required-Stop: $local_fs $remote_fs $syslog $network
  13. # Default-Start: 2 3 4 5
  14. # Default-Stop: 0 1 6
  15. # Short-Description: Starts and stops the Nagios Remote Plugin Executor
  16. # Description: Starts and stops the Nagios Remote Plugin Executor
  17. # so a remote nagios server can run plugins on this host
  18. ### END INIT INFO
  19. NRPE_BIN=@sbindir@/nrpe
  20. NRPE_CFG=@pkgsysconfdir@/nrpe.cfg
  21. LOCK_DIR=@subsyslockdir@
  22. LOCK_FILE=@subsyslockfile@
  23. PID_FILE=@piddir@/nrpe.pid
  24. test -x $NRPE_BIN || exit 5
  25. RETVAL=0
  26. # Default these commands/functions to RedHat/CentOS etc. values
  27. START_CMD="daemon --pidfile $PID_FILE"
  28. STAT_CMD="status nrpe"
  29. QSTAT_CMD="status nrpe >/dev/null 2>&1"
  30. TERM_CMD="killproc -p $PID_FILE $NRPE_BIN -TERM"
  31. HUP_CMD="killproc -p $PID_FILE $NRPE_BIN -HUP"
  32. PRT_STAT="echo"
  33. EXIT_CMD="exit"
  34. # Source the function library
  35. if [ -f /etc/rc.status ]; then
  36. . /etc/rc.status
  37. # Set these commands/functions to SuSE etc. values
  38. START_CMD="startproc -p $PID_FILE"
  39. STAT_CMD="checkproc"
  40. QSTAT_CMD="rc_status"
  41. TERM_CMD="killproc -p $PID_FILE -TERM $NRPE_BIN"
  42. HUP_CMD="killproc -p $PID_FILE -HUP $NRPE_BIN"
  43. PRT_STAT="rc_status -v -r"
  44. EXIT_CMD="rc_exit"
  45. rc_reset
  46. elif [ -f /etc/rc.d/init.d/functions ]; then
  47. . /etc/rc.d/init.d/functions
  48. elif [ -f /etc/init.d/functions ]; then
  49. . /etc/init.d/functions
  50. elif [ -f /lib/lsb/init-functions ]; then
  51. . /lib/lsb/init-functions
  52. START_CMD="start_daemon -p $PID_FILE"
  53. QSTAT_CMD="pidofproc -p $PID_FILE $NRPE_BIN"
  54. PRT_STAT="status_of_proc -p $PID_FILE $NRPE_BIN nrpe"
  55. elif [ -f /etc/rc.d/functions ]; then
  56. . /etc/rc.d/functions
  57. fi
  58. # See how we were called.
  59. case "$1" in
  60. start)
  61. # Start daemons.
  62. echo -n "Starting nrpe: "
  63. $START_CMD $NRPE_BIN -c $NRPE_CFG -d
  64. RETVAL=$?
  65. $PRT_STAT
  66. if [ $RETVAL = 0 ]; then
  67. [ -d $LOCK_DIR ] && touch $LOCK_FILE
  68. fi
  69. ;;
  70. stop)
  71. # Stop daemons.
  72. echo -n "Shutting down nrpe: "
  73. $TERM_CMD
  74. RETVAL=$?
  75. $PRT_STAT
  76. if [ $RETVAL = 0 ]; then
  77. [ -d $LOCK_DIR ] && rm -f $LOCK_FILE
  78. fi
  79. ;;
  80. restart|force-reload)
  81. $0 stop
  82. $0 start
  83. $QSTAT_CMD
  84. ;;
  85. reload)
  86. echo -n "Reloading nrpe: "
  87. $HUP_CMD
  88. RETVAL=$?
  89. $PRT_STAT
  90. ;;
  91. try-restart|condrestart)
  92. $QSTAT_CMD || exit 0
  93. $0 stop
  94. $0 start
  95. $QSTAT_CMD
  96. ;;
  97. status)
  98. $STAT_CMD
  99. RETVAL=$?
  100. ;;
  101. *)
  102. echo "Usage: nrpe {start|stop|restart|reload|try-restart|condrestart|status}"
  103. exit 1
  104. esac
  105. $EXIT_CMD $RETVAL