default-init.in 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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_rc (){ return $RETVAL; }
  41. # Set these commands/functions to SuSE etc. values
  42. START_CMD="startproc -p $PID_FILE"
  43. TERM_CMD="killproc -p $PID_FILE -TERM $NRPE_BIN"
  44. HUP_CMD="killproc -p $PID_FILE -HUP $NRPE_BIN"
  45. PRT_STAT="rc_status -v -r"
  46. STAT_CMD="checkproc -p $PID_FILE $NRPE_BIN"
  47. EXIT_CMD="rc_exit"
  48. rc_reset
  49. elif [ -f /etc/rc.d/init.d/functions ]; then
  50. . /etc/rc.d/init.d/functions
  51. elif [ -f /etc/init.d/functions ]; then
  52. . /etc/init.d/functions
  53. elif [ -f /lib/lsb/init-functions ]; then
  54. . /lib/lsb/init-functions
  55. MSG_CMD="log_daemon_msg"
  56. START_CMD="start_daemon -p $PID_FILE"
  57. PRT_STAT="log_end_msg"
  58. STAT_MSG=
  59. STAT_CMD="status_of_proc -p $PID_FILE $NRPE_BIN nrpe"
  60. elif [ -f /etc/rc.d/functions ]; then
  61. . /etc/rc.d/functions
  62. fi
  63. # See how we were called.
  64. case "$1" in
  65. start)
  66. # Start daemons.
  67. $MSG_CMD "Starting nrpe "
  68. $START_CMD $NRPE_BIN -c $NRPE_CFG -d
  69. RETVAL=$?
  70. if test "$PRT_STAT" = log_end_msg; then
  71. $PRT_STAT $RETVAL
  72. else
  73. _set_rc; $PRT_STAT
  74. fi
  75. if [ $RETVAL = 0 ]; then
  76. [ -d $LOCK_DIR ] && touch $LOCK_FILE || true
  77. fi
  78. ;;
  79. stop)
  80. # Stop daemons.
  81. $MSG_CMD "Shutting down nrpe "
  82. $TERM_CMD
  83. RETVAL=$?
  84. if test "$PRT_STAT" = log_end_msg; then
  85. $PRT_STAT $RETVAL
  86. else
  87. _set_rc; $PRT_STAT
  88. fi
  89. if [ $RETVAL = 0 ]; then
  90. [ -d $LOCK_DIR ] && rm -f $LOCK_FILE
  91. fi
  92. ;;
  93. restart|force-reload)
  94. $0 stop
  95. $0 start
  96. RETVAL=$?
  97. ;;
  98. reload)
  99. $MSG_CMD "Reloading nrpe "
  100. $HUP_CMD
  101. RETVAL=$?
  102. if test "$PRT_STAT" = log_end_msg; then
  103. $PRT_STAT $RETVAL
  104. else
  105. _set_rc; $PRT_STAT
  106. fi
  107. ;;
  108. try-restart|condrestart)
  109. $STAT_CMD || exit 0
  110. $0 stop
  111. $0 start
  112. RETVAL=$?
  113. ;;
  114. status)
  115. $STAT_MSG
  116. $STAT_CMD
  117. RETVAL=$?
  118. if test "$PRT_STAT" != log_end_msg; then
  119. _set_rc; $PRT_STAT
  120. fi
  121. ;;
  122. *)
  123. echo "Usage: nrpe {start|stop|restart|reload|try-restart|condrestart|status}"
  124. exit 1
  125. esac
  126. $EXIT_CMD $RETVAL