default-init.in 3.0 KB

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