Revision: 6611
          http://gar.svn.sourceforge.net/gar/?rev=6611&view=rev
Author:   j_arndt
Date:     2009-09-29 15:45:36 +0000 (Tue, 29 Sep 2009)

Log Message:
-----------
nagios: improved start / stop script, fix in prototype

Modified Paths:
--------------
    csw/mgar/pkg/nagios/trunk/checksums
    csw/mgar/pkg/nagios/trunk/files/CSWnagios.preinstall
    csw/mgar/pkg/nagios/trunk/files/CSWnagios.prototype
    csw/mgar/pkg/nagios/trunk/files/cswnagios

Removed Paths:
-------------
    csw/mgar/pkg/nagios/trunk/files/nagios

Modified: csw/mgar/pkg/nagios/trunk/checksums
===================================================================
--- csw/mgar/pkg/nagios/trunk/checksums 2009-09-29 15:28:52 UTC (rev 6610)
+++ csw/mgar/pkg/nagios/trunk/checksums 2009-09-29 15:45:36 UTC (rev 6611)
@@ -1,9 +1,9 @@
 e407a4b179bd7de72b3e8c21f309f9b7  download/CSWnagios.checkinstall
-db3f392c725ae6e9a3f5a969d2527b41  download/CSWnagios.preinstall
+5185cf1fded86e414e134710f075f4ed  download/CSWnagios.preinstall
 92437323de0cceaa58c6238ec9e6c954  download/CSWnagios.preremove
-8d38acdcd6d31711af14ad09e537ea20  download/CSWnagios.prototype
+4aa71b54c0fa268116a41abc7f3f2b5d  download/CSWnagios.prototype
 e493345589ac2c592c2b958499bc8c20  download/configure.diff
-d3b39178a60cf866a243d4d8f8eabb9b  download/cswnagios
+1d43a15b685160919b82b181c118cbae  download/cswnagios
 f3161bcb7c65f89707ee37b0a8d861d5  download/install-opts.diff
 3566167cc60ddeaad34e7d2e26ed4a58  download/nagios-3.2.0.tar.gz
 91407bdea2047b6ff5a1542550933144  download/patch.diff

Modified: csw/mgar/pkg/nagios/trunk/files/CSWnagios.preinstall
===================================================================
--- csw/mgar/pkg/nagios/trunk/files/CSWnagios.preinstall        2009-09-29 
15:28:52 UTC (rev 6610)
+++ csw/mgar/pkg/nagios/trunk/files/CSWnagios.preinstall        2009-09-29 
15:45:36 UTC (rev 6611)
@@ -4,8 +4,31 @@
 # 2007-09-11 Fix PKG_INSTALL_ROOT usage.  BASEDIR is not used for non
 #            relocatable packages.
 
+
 echo "Executing preinstall"
 
+cat << EOF
+
+=======================================================================
+
+From Nagios 3.2.0 on the configuration and log files for the OpenCSW 
+package are stored in /etc/opt/csw/nagios/ and /var/opt/csw/nagios/.
+
+Changes you made to your existing config will automatically 
+moved to the new location.
+
+
+Please be aware, that it's very likely that you have to change your
+nagios.cfg to that changes.
+
+            Installation will proceed in 30 seconds. 
+             Press CTRL+C if you want to stop now.
+
+=======================================================================
+EOF
+
+sleep 30
+
 #If installing package on a filesystem tree not running the OS; then exit.
 if [ ! x"$PKG_INSTALL_ROOT" = x"" ] ; then exit 0 ; fi
 
@@ -31,17 +54,5 @@
         /usr/sbin/usermod -G nagioscm nagios
 fi
 
-cat << EOF
 
-=======================================================================
-
-Configuration files were moved from /opt/csw/nagios/etc/ to
-/etc/opt/csw/nagios/.
-
-Changes which were made to the existing config will automatically 
-moved to the new location.
-
-=======================================================================
-EOF
-
 exit 0

Modified: csw/mgar/pkg/nagios/trunk/files/CSWnagios.prototype
===================================================================
--- csw/mgar/pkg/nagios/trunk/files/CSWnagios.prototype 2009-09-29 15:28:52 UTC 
(rev 6610)
+++ csw/mgar/pkg/nagios/trunk/files/CSWnagios.prototype 2009-09-29 15:45:36 UTC 
(rev 6611)
@@ -4,7 +4,7 @@
 d none /opt/csw/nagios/bin 0755 nagios nagios
 f none /opt/csw/nagios/bin/nagios 0754 nagios nagios
 f none /opt/csw/nagios/bin/nagiostats 0754 nagios nagios
-f none /opt/csw/nagios/bin/p1.pl 075 nagios nagios
+f none /opt/csw/nagios/bin/p1.pl 0754 nagios nagios
 d none /etc/opt/csw/nagios 0755 nagios nagios
 f cswpreserveconf /etc/opt/csw/nagios/cgi.cfg.CSW 0644 nagios nagios
 f none /etc/opt/csw/nagios/httpd-nagios.conf 0644 nagios nagios

Modified: csw/mgar/pkg/nagios/trunk/files/cswnagios
===================================================================
--- csw/mgar/pkg/nagios/trunk/files/cswnagios   2009-09-29 15:28:52 UTC (rev 
6610)
+++ csw/mgar/pkg/nagios/trunk/files/cswnagios   2009-09-29 15:45:36 UTC (rev 
6611)
@@ -28,26 +28,28 @@
 #
 # Modified for CSW by Alex Moore 2006-02-27
 # Modified for OpenCSW by Juergen Arndt 2009-03-11
+#
+# 2009-09-24 Alexander Skwar <alexan...@skwar.name>
+#  - Load Solaris SMF file, if present
+#  - Use SMF exitcodes, if SMF file was loaded
+#  - use printf instead of "echo -n"
 
 #FMRI application       # FMRI path for service, see 
http://wiki.opencsw.org/cswclassutils-package#toc0
 
+# Load Solaris SMF Variables
+test -r /lib/svc/share/smf_include.sh && . /lib/svc/share/smf_include.sh
+
 status_nagios ()
 {
 
-       if test ! -f $NagiosRun; then
-               echo "No lock file found in $NagiosRun"
-               return 1
-       fi
-
-       NagiosPID=`head -n 1 $NagiosRun`
        if test -x $NagiosCGI/daemonchk.cgi; then
-               if $NagiosCGI/daemonchk.cgi -l $NagiosRun; then
+               if $NagiosCGI/daemonchk.cgi -l $NagiosRunFile; then
                        return 0
                else
                        return 1
                fi
        else
-               if ps -p $NagiosPID; then
+               if ps -p $NagiosPID > /dev/null 2>&1; then
                        return 0
                else
                        return 1
@@ -57,20 +59,40 @@
        return 1
 }
 
+printstatus_nagios()
+{
 
+       if status_nagios $1 $2; then
+               echo "nagios (pid $NagiosPID) is running..."
+       else
+               echo "nagios is not running"
+       fi
+}
+
 killproc_nagios ()
 {
 
-        if [ ! -f $NagiosRun ]; then
-               echo "No lock file found in $NagiosRun"
+        if [ ! -f $NagiosRunFile ]; then
+               echo "No lock file found in $NagiosRunFile"
                return 1
        fi
 
-       NagiosPID=`head -n 1 $NagiosRun`
+       NagiosPID=`head -n 1 $NagiosRunFile`
        kill $2 $NagiosPID
 }
 
+pid_nagios ()
+{
 
+       if test ! -f $NagiosRunFile; then
+               echo "No lock file found in $NagiosRunFile"
+               test -z "$SMF_EXIT_ERR_FATAL" && exit 1
+               test -n "$SMF_EXIT_ERR_FATAL" && exit $SMF_EXIT_ERR_FATAL
+       fi
+
+       NagiosPID=`head -n 1 $NagiosRunFile`
+}
+
 # Source function library
 # Solaris doesn't have an rc.d directory, so do a test first
 if [ -f /etc/rc.d/init.d/functions ]; then
@@ -81,91 +103,146 @@
 
 prefix=/opt/csw/nagios
 exec_prefix=${prefix}
+NagiosVarDir=/var/${prefix}
 NagiosBin=${exec_prefix}/bin/nagios
-NagiosCfg=${prefix}/etc/nagios.cfg
-NagiosLog=${prefix}/var/status.log
-NagiosTmp=${prefix}/var/nagios.tmp
-NagiosSav=${prefix}/var/status.sav
-NagiosCmd=${prefix}/var/rw/nagios.cmd
-NagiosVar=${prefix}/var
-NagiosRun=${prefix}/var/nagios.lock
-NagiosLckDir=/var/lock/subsys
-NagiosLckFile=nagios
-NagiosCGI=${exec_prefix}/sbin
-Nagios=nagios
-          
+NagiosCfgFile=/etc/${prefix}/nagios.cfg
+NagiosStatusFile=${NagiosVarDir}/status.dat
+NagiosRetentionFile=${NagiosVarDir}/retention.dat
+NagiosCommandFile=${NagiosVarDir}/rw/nagios.cmd
+NagiosRunFile=${NagiosVarDir}/nagios.lock
+NagiosLockDir=/var/lock/subsys
+NagiosLockFile=nagios
+NagiosCGIDir=${exec_prefix}/sbin
+NagiosUser=nagios
+NagiosGroup=nagios          
 
 # Check that nagios exists.
-test -f $NagiosBin || exit 0
+if [ ! -f $NagiosBin ]; then
+    echo "Executable file $NagiosBin not found.  Exiting."
+    test -z "$SMF_EXIT_ERR_FATAL" && exit 1
+    test -n "$SMF_EXIT_ERR_FATAL" && exit $SMF_EXIT_ERR_FATAL
+fi
 
 # Check that nagios.cfg exists.
-test -f $NagiosCfg || exit 0
+if [ ! -f $NagiosCfgFile ]; then
+    echo "Configuration file $NagiosCfgFile not found.  Exiting."
+    test -z "$SMF_EXIT_ERR_CONFIG" && exit 1
+    test -n "$SMF_EXIT_ERR_CONFIG" && exit $SMF_EXIT_ERR_CONFIG
+fi
           
 # See how we were called.
 case "$1" in
 
        start)
-               echo "Starting network monitor: nagios"
-               su - $Nagios -c "touch $NagiosVar/nagios.log $NagiosSav"
-               rm -f $NagiosCmd
-               $NagiosBin -d $NagiosCfg
-               if [ -d $NagiosLckDir ]; then touch 
$NagiosLckDir/$NagiosLckFile; fi
-               sleep 1
-               status_nagios nagios
+               printf "Starting nagios:"
+               $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
+               if [ $? -eq 0 ]; then
+                       su - $NagiosUser -c "touch $NagiosVarDir/nagios.log 
$NagiosRetentionFile"
+                       rm -f $NagiosCommandFile
+                       touch $NagiosRunFile
+                       chown $NagiosUser:$NagiosGroup $NagiosRunFile
+                       $NagiosBin -d $NagiosCfgFile
+                       if [ -d $NagiosLockDir ]; then touch 
$NagiosLockDir/$NagiosLockFile; fi
+                       echo " done."
+                       test -z "$SMF_EXIT_OK" && exit 0
+                       test -n "$SMF_EXIT_OK" && exit $SMF_EXIT_OK
+               else
+                       echo "CONFIG ERROR!  Start aborted.  Check your Nagios 
configuration."
+                       test -z "$SMF_EXIT_ERR_CONFIG" && exit 1
+                       test -n "$SMF_EXIT_ERR_CONFIG" && exit 
$SMF_EXIT_ERR_CONFIG
+               fi
                ;;
 
        stop)
-               echo "Stopping network monitor: nagios"
+               printf "Stopping nagios: "
+
+               pid_nagios
                killproc_nagios nagios
-               rm -f $NagiosLog $NagiosTmp $NagiosRun 
$NagiosLckDir/$NagiosLckFile $NagiosCmd
+
+               # now we have to wait for nagios to exit and remove its
+               # own NagiosRunFile, otherwise a following "start" could
+               # happen, and then the exiting nagios will remove the
+               # new NagiosRunFile, allowing multiple nagios daemons
+               # to (sooner or later) run - John Sellens
+               #printf 'Waiting for nagios to exit .'
+               for i in 1 2 3 4 5 6 7 8 9 10 ; do
+                   if status_nagios > /dev/null; then
+                       printf '.'
+                       sleep 1
+                   else
+                       break
+                   fi
+               done
+               if status_nagios > /dev/null; then
+                   echo ''
+                   echo 'Warning - nagios did not exit in a timely manner'
+               else
+                   echo 'done.'
+               fi
+
+               rm -f $NagiosStatusFile $NagiosRunFile 
$NagiosLockDir$NagiosLockFile $NagiosCommandFile
                ;;
 
        status)
-               status_nagios nagios
+               pid_nagios
+               printstatus_nagios nagios
                ;;
 
+       checkconfig)
+               printf "Running configuration check..."
+               $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
+               if [ $? -eq 0 ]; then
+                       echo " OK."
+               else
+                       echo " CONFIG ERROR!  Check your Nagios configuration."
+                       test -z "$SMF_EXIT_ERR_CONFIG" && exit 1
+                       test -n "$SMF_EXIT_ERR_CONFIG" && exit 
$SMF_EXIT_ERR_CONFIG
+               fi
+               ;;
+
        restart)
                printf "Running configuration check..."
-               $NagiosBin -v $NagiosCfg > /dev/null 2>&1;
+               $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
                if [ $? -eq 0 ]; then
-                       echo "done"
-                       $0 stop
-                       $0 start
+                       echo "done."
+                       "$0" stop
+                       "$0" start
                else
-                       $NagiosBin -v $NagiosCfg
-                       echo "failed - aborting restart."
-                       exit 1
+                       echo " CONFIG ERROR!  Restart aborted.  Check your 
Nagios configuration."
+                       test -z "$SMF_EXIT_ERR_CONFIG" && exit 1
+                       test -n "$SMF_EXIT_ERR_CONFIG" && exit 
$SMF_EXIT_ERR_CONFIG
                fi
                ;;
 
        reload|force-reload)
                printf "Running configuration check..."
-               $NagiosBin -v $NagiosCfg > /dev/null 2>&1;
+               $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
                if [ $? -eq 0 ]; then
-                       echo "done"
-                       if test ! -f $NagiosRun; then
-                               $0 start
+                       echo "done."
+                       if test ! -f $NagiosRunFile; then
+                               "$0" start
                        else
-                               NagiosPID=`head -n 1 $NagiosRun`
+                               pid_nagios
                                if status_nagios > /dev/null; then
                                        printf "Reloading nagios 
configuration..."
                                        killproc_nagios nagios -HUP
                                        echo "done"
                                else
-                                       $0 stop
-                                       $0 start
+                                       "$0" stop
+                                       "$0" start
                                fi
                        fi
                else
-                       $NagiosBin -v $NagiosCfg
-                       echo "failed - aborting reload."
-                       exit 1
+                       echo " CONFIG ERROR!  Reload aborted.  Check your 
Nagios configuration."
+                       test -z "$SMF_EXIT_ERR_CONFIG" && exit 1
+                       test -n "$SMF_EXIT_ERR_CONFIG" && exit 
$SMF_EXIT_ERR_CONFIG
                fi
                ;;
 
        *)
-               echo "Usage: nagios 
{start|stop|restart|reload|force-reload|status}"
-               exit 1
+               echo "Usage: nagios 
{start|stop|restart|reload|force-reload|status|checkconfig}"
+               test -z "$SMF_EXIT_ERR_FATAL" && exit 1
+               test -n "$SMF_EXIT_ERR_FATAL" && exit $SMF_EXIT_ERR_FATAL
                ;;
 
 esac

Deleted: csw/mgar/pkg/nagios/trunk/files/nagios
===================================================================
--- csw/mgar/pkg/nagios/trunk/files/nagios      2009-09-29 15:28:52 UTC (rev 
6610)
+++ csw/mgar/pkg/nagios/trunk/files/nagios      2009-09-29 15:45:36 UTC (rev 
6611)
@@ -1,171 +0,0 @@
-#!/bin/sh
-# 
-# chkconfig: 345 99 01
-# description: Nagios network monitor
-#
-# File : nagios
-#
-# Author : Jorge Sanchez Aymar (jsanc...@lanchile.cl)
-# 
-# Changelog :
-#
-# 1999-07-09 Karl DeBisschop <kdebissc...@infoplease.com>
-#  - setup for autoconf
-#  - add reload function
-# 1999-08-06 Ethan Galstad <nag...@nagios.org>
-#  - Added configuration info for use with RedHat's chkconfig tool
-#    per Fran Boon's suggestion
-# 1999-08-13 Jim Popovitch <jim...@rocketship.com>
-#  - added variable for nagios/var directory
-#  - cd into nagios/var directory before creating tmp files on startup
-# 1999-08-16 Ethan Galstad <nag...@nagios.org>
-#  - Added test for rc.d directory as suggested by Karl DeBisschop
-# 2000-07-23 Karl DeBisschop <kdebissc...@users.sourceforge.net>
-#  - Clean out redhat macros and other dependencies
-#
-# Description: Starts and stops the Nagios monitor
-#              used to provide network services status.
-#
-# Modified for CSW by Alex Moore 2006-02-27
-
-
-status_nagios ()
-{
-
-       if test ! -f $NagiosRun; then
-               echo "No lock file found in $NagiosRun"
-               return 1
-       fi
-
-       NagiosPID=`head -n 1 $NagiosRun`
-       if test -x $NagiosCGI/daemonchk.cgi; then
-               if $NagiosCGI/daemonchk.cgi -l $NagiosRun; then
-                       return 0
-               else
-                       return 1
-               fi
-       else
-               if ps -p $NagiosPID; then
-                       return 0
-               else
-                       return 1
-               fi
-       fi
-
-       return 1
-}
-
-
-killproc_nagios ()
-{
-
-        if [ ! -f $NagiosRun ]; then
-               echo "No lock file found in $NagiosRun"
-               return 1
-       fi
-
-       NagiosPID=`head -n 1 $NagiosRun`
-       kill $2 $NagiosPID
-}
-
-
-# Source function library
-# Solaris doesn't have an rc.d directory, so do a test first
-if [ -f /etc/rc.d/init.d/functions ]; then
-       . /etc/rc.d/init.d/functions
-elif [ -f /etc/init.d/functions ]; then
-       . /etc/init.d/functions
-fi
-
-prefix=/opt/csw/nagios
-exec_prefix=${prefix}
-NagiosBin=${exec_prefix}/bin/nagios
-NagiosCfg=${prefix}/etc/nagios.cfg
-NagiosLog=${prefix}/var/status.log
-NagiosTmp=${prefix}/var/nagios.tmp
-NagiosSav=${prefix}/var/status.sav
-NagiosCmd=${prefix}/var/rw/nagios.cmd
-NagiosVar=${prefix}/var
-NagiosRun=${prefix}/var/nagios.lock
-NagiosLckDir=/var/lock/subsys
-NagiosLckFile=nagios
-NagiosCGI=${exec_prefix}/sbin
-Nagios=nagios
-          
-
-# Check that nagios exists.
-test -f $NagiosBin || exit 0
-
-# Check that nagios.cfg exists.
-test -f $NagiosCfg || exit 0
-          
-# See how we were called.
-case "$1" in
-
-       start)
-               echo "Starting network monitor: nagios"
-               su - $Nagios -c "touch $NagiosVar/nagios.log $NagiosSav"
-               rm -f $NagiosCmd
-               $NagiosBin -d $NagiosCfg
-               if [ -d $NagiosLckDir ]; then touch 
$NagiosLckDir/$NagiosLckFile; fi
-               sleep 1
-               status_nagios nagios
-               ;;
-
-       stop)
-               echo "Stopping network monitor: nagios"
-               killproc_nagios nagios
-               rm -f $NagiosLog $NagiosTmp $NagiosRun 
$NagiosLckDir/$NagiosLckFile $NagiosCmd
-               ;;
-
-       status)
-               status_nagios nagios
-               ;;
-
-       restart)
-               printf "Running configuration check..."
-               $NagiosBin -v $NagiosCfg > /dev/null 2>&1;
-               if [ $? -eq 0 ]; then
-                       echo "done"
-                       $0 stop
-                       $0 start
-               else
-                       $NagiosBin -v $NagiosCfg
-                       echo "failed - aborting restart."
-                       exit 1
-               fi
-               ;;
-
-       reload|force-reload)
-               printf "Running configuration check..."
-               $NagiosBin -v $NagiosCfg > /dev/null 2>&1;
-               if [ $? -eq 0 ]; then
-                       echo "done"
-                       if test ! -f $NagiosRun; then
-                               $0 start
-                       else
-                               NagiosPID=`head -n 1 $NagiosRun`
-                               if status_nagios > /dev/null; then
-                                       printf "Reloading nagios 
configuration..."
-                                       killproc_nagios nagios -HUP
-                                       echo "done"
-                               else
-                                       $0 stop
-                                       $0 start
-                               fi
-                       fi
-               else
-                       $NagiosBin -v $NagiosCfg
-                       echo "failed - aborting reload."
-                       exit 1
-               fi
-               ;;
-
-       *)
-               echo "Usage: nagios 
{start|stop|restart|reload|force-reload|status}"
-               exit 1
-               ;;
-
-esac
-  
-# End of this script


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.
_______________________________________________
devel mailing list
devel@lists.opencsw.org
https://lists.opencsw.org/mailman/listinfo/devel

Reply via email to