Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Paste Description for /opt/local/nagios-3.2.0/method/n

Original version of the "init" script, as supplied by Nagios

/opt/local/nagios-3.2.0/method/n
2009 year 9 month 24 day Thursday 05:59:33 MDT 

This post has 1 comment thread shown at the end of this page.

  1. #!/bin/sh
  2. #
  3. # chkconfig: 345 99 01
  4. # description: Nagios network monitor
  5. #
  6. # File : nagios
  7. #
  8. # Author : Jorge Sanchez Aymar (jsanchez@lanchile.cl)
  9. #
  10. # Changelog :
  11. #
  12. # 1999-07-09 Karl DeBisschop <kdebisschop@infoplease.com>
  13. #  - setup for autoconf
  14. #  - add reload function
  15. # 1999-08-06 Ethan Galstad <egalstad@nagios.org>
  16. #  - Added configuration info for use with RedHat's chkconfig tool
  17. #    per Fran Boon's suggestion
  18. # 1999-08-13 Jim Popovitch <jimpop@rocketship.com>
  19. #  - added variable for nagios/var directory
  20. #  - cd into nagios/var directory before creating tmp files on startup
  21. # 1999-08-16 Ethan Galstad <egalstad@nagios.org>
  22. #  - Added test for rc.d directory as suggested by Karl DeBisschop
  23. # 2000-07-23 Karl DeBisschop <kdebisschop@users.sourceforge.net>
  24. #  - Clean out redhat macros and other dependencies
  25. # 2003-01-11 Ethan Galstad <egalstad@nagios.org>
  26. #  - Updated su syntax (Gary Miller)
  27. #
  28. # Description: Starts and stops the Nagios monitor
  29. #              used to provide network services status.
  30. #
  31.  
  32. status_nagios ()
  33. {
  34.  
  35.         if test -x $NagiosCGI/daemonchk.cgi; then
  36.                 if $NagiosCGI/daemonchk.cgi -l $NagiosRunFile; then
  37.                         return 0
  38.                 else
  39.                         return 1
  40.                 fi
  41.         else
  42.                 if ps -p $NagiosPID > /dev/null 2>&1; then
  43.                         return 0
  44.                 else
  45.                         return 1
  46.                 fi
  47.         fi
  48.  
  49.         return 1
  50. }
  51.  
  52.  
  53. printstatus_nagios()
  54. {
  55.  
  56.         if status_nagios $1 $2; then
  57.                 echo "nagios (pid $NagiosPID) is running..."
  58.         else
  59.                 echo "nagios is not running"
  60.         fi
  61. }
  62.  
  63.  
  64. killproc_nagios ()
  65. {
  66.  
  67.         kill $2 $NagiosPID
  68.  
  69. }
  70.  
  71.  
  72. pid_nagios ()
  73. {
  74.  
  75.         if test ! -f $NagiosRunFile; then
  76.                 echo "No lock file found in $NagiosRunFile"
  77.                 exit 1
  78.         fi
  79.  
  80.         NagiosPID=`head -n 1 $NagiosRunFile`
  81. }
  82.  
  83.  
  84. # Source function library
  85. # Solaris doesn't have an rc.d directory, so do a test first
  86. if [ -f /etc/rc.d/init.d/functions ]; then
  87.         . /etc/rc.d/init.d/functions
  88. elif [ -f /etc/init.d/functions ]; then
  89.         . /etc/init.d/functions
  90. fi
  91.  
  92. prefix=/opt/local/nagios-3.2.0
  93. exec_prefix=${prefix}
  94. NagiosBin=${exec_prefix}/bin/nagios
  95. NagiosCfgFile=${prefix}/etc/nagios.cfg
  96. NagiosStatusFile=/opt/local/nagios-3.2.0/var/status.dat
  97. NagiosRetentionFile=/opt/local/nagios-3.2.0/var/retention.dat
  98. NagiosCommandFile=/opt/local/nagios-3.2.0/var/rw/nagios.cmd
  99. NagiosVarDir=/opt/local/nagios-3.2.0/var
  100. NagiosRunFile=/opt/local/nagios-3.2.0/var/nagios.lock
  101. NagiosLockDir=/var/lock/subsys
  102. NagiosLockFile=nagios
  103. NagiosCGIDir=${exec_prefix}/sbin
  104. NagiosUser=webservd
  105. NagiosGroup=webservd
  106.          
  107.  
  108. # Check that nagios exists.
  109. if [ ! -f $NagiosBin ]; then
  110.     echo "Executable file $NagiosBin not found.  Exiting."
  111.     exit 1
  112. fi
  113.  
  114. # Check that nagios.cfg exists.
  115. if [ ! -f $NagiosCfgFile ]; then
  116.     echo "Configuration file $NagiosCfgFile not found.  Exiting."
  117.     exit 1
  118. fi
  119.          
  120. # See how we were called.
  121. case "$1" in
  122.  
  123.         start)
  124.                 echo -n "Starting nagios:"
  125.                 $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
  126.                 if [ $? -eq 0 ]; then
  127.                         su - $NagiosUser -c "touch $NagiosVarDir/nagios.log $NagiosRetentionFile"
  128.                         rm -f $NagiosCommandFile
  129.                         touch $NagiosRunFile
  130.                         chown $NagiosUser:$NagiosGroup $NagiosRunFile
  131.                         $NagiosBin -d $NagiosCfgFile
  132.                         if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi
  133.                         echo " done."
  134.                         exit 0
  135.                 else
  136.                         echo "CONFIG ERROR!  Start aborted.  Check your Nagios configuration."
  137.                         exit 1
  138.                 fi
  139.                 ;;
  140.  
  141.         stop)
  142.                 echo -n "Stopping nagios: "
  143.  
  144.                 pid_nagios
  145.                 killproc_nagios nagios
  146.  
  147.                 # now we have to wait for nagios to exit and remove its
  148.                 # own NagiosRunFile, otherwise a following "start" could
  149.                 # happen, and then the exiting nagios will remove the
  150.                 # new NagiosRunFile, allowing multiple nagios daemons
  151.                 # to (sooner or later) run - John Sellens
  152.                 #echo -n 'Waiting for nagios to exit .'
  153.                 for i in 1 2 3 4 5 6 7 8 9 10 ; do
  154.                     if status_nagios > /dev/null; then
  155.                         echo -n '.'
  156.                         sleep 1
  157.                     else
  158.                         break
  159.                     fi
  160.                 done
  161.                 if status_nagios > /dev/null; then
  162.                     echo ''
  163.                     echo 'Warning - nagios did not exit in a timely manner'
  164.                 else
  165.                     echo 'done.'
  166.                 fi
  167.  
  168.                 rm -f $NagiosStatusFile $NagiosRunFile $NagiosLockDir/$NagiosLockFile $NagiosCommandFile
  169.                 ;;
  170.  
  171.         status)
  172.                 pid_nagios
  173.                 printstatus_nagios nagios
  174.                 ;;
  175.  
  176.         checkconfig)
  177.                 printf "Running configuration check..."
  178.                 $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
  179.                 if [ $? -eq 0 ]; then
  180.                         echo " OK."
  181.                 else
  182.                         echo " CONFIG ERROR!  Check your Nagios configuration."
  183.                         exit 1
  184.                 fi
  185.                 ;;
  186.  
  187.         restart)
  188.                 printf "Running configuration check..."
  189.                 $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
  190.                 if [ $? -eq 0 ]; then
  191.                         echo "done."
  192.                         $0 stop
  193.                         $0 start
  194.                 else
  195.                         echo " CONFIG ERROR!  Restart aborted.  Check your Nagios configuration."
  196.                         exit 1
  197.                 fi
  198.                 ;;
  199.  
  200.         reload|force-reload)
  201.                 printf "Running configuration check..."
  202.                 $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
  203.                 if [ $? -eq 0 ]; then
  204.                         echo "done."
  205.                         if test ! -f $NagiosRunFile; then
  206.                                 $0 start
  207.                         else
  208.                                 pid_nagios
  209.                                 if status_nagios > /dev/null; then
  210.                                         printf "Reloading nagios configuration..."
  211.                                         killproc_nagios nagios -HUP
  212.                                         echo "done"
  213.                                 else
  214.                                         $0 stop
  215.                                         $0 start
  216.                                 fi
  217.                         fi
  218.                 else
  219.                         echo " CONFIG ERROR!  Reload aborted.  Check your Nagios configuration."
  220.                         exit 1
  221.                 fi
  222.                 ;;
  223.  
  224.         *)
  225.                 echo "Usage: nagios {start|stop|restart|reload|force-reload|status|checkconfig}"
  226.                 exit 1
  227.                 ;;
  228.  
  229. esac
  230.  
  231. # End of this script

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments on this paste

/opt/local/nagios-3.2.0/method/n (#1577792)

Posted By: Alexander (alexander@skwar.name)

Posted: September 24th, 2009 at 6:01am MDT

That's what is supplied by Nagios 3.2.0.

worth-right
fantasy-obligation