Page 3 of 5
Re: Upgrading from 3.5.1 to 4.0.0
Posted: Thu Sep 26, 2013 5:13 pm
by mlong
abrist wrote:No, it looks like you are doing everything right.
mlong: Can you post the init script you are currently using in code wraps?
Here it is. I have made no changes to it from the 3.5.1 installation.
Code: Select all
#!/bin/sh
#
# chkconfig: 345 99 01
# description: Nagios network monitor
#
# File : nagios
#
# Author : Jorge Sanchez Aymar (jsanchez@lanchile.cl)
#
# Changelog :
#
# 1999-07-09 Karl DeBisschop <kdebisschop@infoplease.com>
# - setup for autoconf
# - add reload function
# 1999-08-06 Ethan Galstad <egalstad@nagios.org>
# - Added configuration info for use with RedHat's chkconfig tool
# per Fran Boon's suggestion
# 1999-08-13 Jim Popovitch <jimpop@rocketship.com>
# - added variable for nagios/var directory
# - cd into nagios/var directory before creating tmp files on startup
# 1999-08-16 Ethan Galstad <egalstad@nagios.org>
# - Added test for rc.d directory as suggested by Karl DeBisschop
# 2000-07-23 Karl DeBisschop <kdebisschop@users.sourceforge.net>
# - Clean out redhat macros and other dependencies
# 2003-01-11 Ethan Galstad <egalstad@nagios.org>
# - Updated su syntax (Gary Miller)
#
# Description: Starts and stops the Nagios monitor
# used to provide network services status.
#
# Load any extra environment variables for Nagios and its plugins
if test -f /etc/sysconfig/nagios; then
. /etc/sysconfig/nagios
fi
status_nagios ()
{
if test -x $NagiosCGI/daemonchk.cgi; then
if $NagiosCGI/daemonchk.cgi -l $NagiosRunFile; then
return 0
else
return 1
fi
else
if ps -p $NagiosPID > /dev/null 2>&1; then
return 0
else
return 1
fi
fi
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 ()
{
kill $2 $NagiosPID
}
pid_nagios ()
{
if test ! -f $NagiosRunFile; then
echo "No lock file found in $NagiosRunFile"
exit 1
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
. /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
prefix=/usr/local/nagios
exec_prefix=${prefix}
NagiosBin=${exec_prefix}/bin/nagios
NagiosCfgFile=${prefix}/etc/nagios.cfg
NagiosStatusFile=${prefix}/var/status.dat
NagiosRetentionFile=${prefix}/var/retention.dat
NagiosCommandFile=${prefix}/var/rw/nagios.cmd
NagiosVarDir=${prefix}/var
NagiosRunFile=${prefix}/var/nagios.lock
NagiosLockDir=/var/lock/subsys
NagiosLockFile=nagios
NagiosCGIDir=${exec_prefix}/sbin
NagiosUser=nagios
NagiosGroup=nagios
# Check that nagios exists.
if [ ! -f $NagiosBin ]; then
echo "Executable file $NagiosBin not found. Exiting."
exit 1
fi
# Check that nagios.cfg exists.
if [ ! -f $NagiosCfgFile ]; then
echo "Configuration file $NagiosCfgFile not found. Exiting."
exit 1
fi
# See how we were called.
case "$1" in
start)
echo -n "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."
exit 0
else
echo "CONFIG ERROR! Start aborted. Check your Nagios configuration."
exit 1
fi
;;
stop)
echo -n "Stopping nagios: "
pid_nagios
killproc_nagios nagios
# 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
#echo -n '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
echo -n '.'
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)
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."
exit 1
fi
;;
restart)
printf "Running configuration check..."
$NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
if [ $? -eq 0 ]; then
echo "done."
$0 stop
$0 start
else
echo " CONFIG ERROR! Restart aborted. Check your Nagios configuration."
exit 1
fi
;;
reload|force-reload)
printf "Running configuration check..."
$NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
if [ $? -eq 0 ]; then
echo "done."
if test ! -f $NagiosRunFile; then
$0 start
else
pid_nagios
if status_nagios > /dev/null; then
printf "Reloading nagios configuration..."
killproc_nagios nagios -HUP
echo "done"
else
$0 stop
$0 start
fi
fi
else
echo " CONFIG ERROR! Reload aborted. Check your Nagios configuration."
exit 1
fi
;;
*)
echo "Usage: nagios {start|stop|restart|reload|force-reload|status|checkconfig}"
exit 1
;;
esac
# End of this script
Re: Upgrading from 3.5.1 to 4.0.0
Posted: Thu Sep 26, 2013 5:15 pm
by mlong
magna.vis wrote:Looks like this guy may have some input as well:
http://roger.steneteg.org/492/installin ... om-source/
I'm also thinking about cloning my current setup, and upgrading without doing the make install-init command and seeing if it still works. If I get around to it in the next couple of days, I'll post my results.
And here it is in code brackets:
Code: Select all
#! /bin/sh
### BEGIN INIT INFO
# Provides: nagios
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop Nagios monitoring server
# Description: Nagios is a service monitoring system
### END INIT INFO
# Author: Foo Bar <roger@steneteg.org>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Nagios monitoring system"
NAME=nagios
PREFIX=/srv/nagios
STATEDIR=/var/nagios
CONFIGDIR=/etc/nagios
CONFIGFILE="$CONFIGDIR/nagios.cfg"
DAEMON="${PREFIX}/bin/${NAME}"
DAEMON_ARGS="-d $CONFIGFILE"
SCRIPTNAME=/etc/init.d/$NAME
PIDFILE=/var/run/$NAME.pid
USER="nagios"
GROUP="nagios"
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions
check_config() {
RESULTFILE="$STATEDIR/configcheck$$"
CHECKRESULT=`$DAEMON -v $CONFIGFILE > $RESULTFILE`
WARN=`grep ^"Total Warnings:" $RESULTFILE | awk -F: '{print $2}' |sed s/' '//g`
ERR=`grep ^"Total Errors:" $RESULTFILE | awk -F: '{print $2}' |sed s/' '//g`
if test "${WARN}" = "0" && test "${ERR}" = "0"; then
echo "OK - Configuration check verified"
return 0
else
cat $RESULTFILE
exit 8
fi
}
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
test -x $DAEMON || exit 2
test -f $CONFIGGILE || exit 2
if test "$1" = "checkconfig"; then
check_config
fi
echo -n "Starting $NAME .."
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 1
start-stop-daemon --start --quiet --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS || return 2
echo ". $NAME started"
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
echo -n "Stopping $NAME .."
# start-stop-daemon --stop --quiet --retry=5 --pidfile $PIDFILE --name $NAME
# RETVAL="$?"
# [ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=5 --exec $DAEMON
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
echo ". $NAME stopped"
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
check_config
# This does not seem to be working
#start-stop-daemon --stop --signal HUP --quiet --pidfile $PIDFILE --name $NAME
echo "There is something wrong with the reload function, use restart instead"
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start "checkconfig"
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
log_daemon_msg "Reloading $DESC" "$NAME"
do_reload
log_end_msg $?
;;
restart)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
check_config
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
exit 3
;;
esac
It does seem to work without running the make install-init command.
Re: Upgrading from 3.5.1 to 4.0.0
Posted: Fri Sep 27, 2013 2:16 am
by jbowen7
In ubuntu 12.04, installed from the repos (3.2.3)
my functions are at:
/lib/lsb/init-functions
it's worth editing /etc/init.d/nagios with that
Re: Upgrading from 3.5.1 to 4.0.0
Posted: Fri Sep 27, 2013 9:40 am
by abrist
Yeah, but you will run into other issues (status, runuser, etc). I will try to get Ludmil to post a copy of the init script we hacked out the other night. It is not perfect, but it does work.
Re: Upgrading from 3.5.1 to 4.0.0
Posted: Fri Sep 27, 2013 9:43 am
by lmiltchev
Here you go... Let us know if it worked for you.
Code: Select all
#!/bin/sh
# Nagios Startup script for the Nagios monitoring daemon
#
# chkconfig: - 85 15
# description: Nagios is a service monitoring system
# processname: nagios
# config: /etc/nagios/nagios.cfg
# pidfile: /var/nagios/nagios.pid
#
### BEGIN INIT INFO
# Provides: nagios
# Required-Start: $local_fs $syslog $network
# Required-Stop: $local_fs $syslog $network
# Short-Description: start and stop Nagios monitoring server
# Description: Nagios is is a service monitoring system
### END INIT INFO
# Source function library.
# . /etc/rc.d/init.d/functions
. /lib/lsb/init-functions
prefix="/usr/local/nagios"
exec_prefix="${prefix}"
exec="${exec_prefix}/bin/nagios"
prog="nagios"
config="${prefix}/etc/nagios.cfg"
pidfile="${prefix}/var/nagios.lock"
user="nagios"
group="nagios"
checkconfig="false"
ramdiskdir="/var/nagios/ramcache"
test -e /etc/sysconfig/$prog && . /etc/sysconfig/$prog
lockfile=/var/lock/$prog
USE_RAMDISK=${USE_RAMDISK:-0}
if test "$USE_RAMDISK" -ne 0 && test "$RAMDISK_SIZE"X != "X"; then
ramdisk=`mount |grep "$ramdiskdir type tmpfs"`
if [ "$ramdisk"X == "X" ]; then
mkdir -p -m 0755 $ramdiskdir
mount -t tmpfs -o size=${RAMDISK_SIZE}m tmpfs $ramdiskdir
mkdir -p -m 0755 $ramdiskdir/checkresults
chown -R $user:$group $ramdiskdir
fi
fi
check_config() {
TMPFILE="/tmp/.configtest.$$"
/usr/sbin/service nagios configtest > "$TMPFILE"
WARN=`grep ^"Total Warnings:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g`
ERR=`grep ^"Total Errors:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g`
if test "$WARN" = "0" && test "${ERR}" = "0"; then
echo "OK - Configuration check verified" > /var/run/nagios.configtest
chmod 0644 /var/run/nagios.configtest
/bin/rm "$TMPFILE"
return 0
else
# We'll write out the errors to a file we can have a
# script watching for
echo "WARNING: Errors in config files - see log for details: $TMPFILE" > /var/run/nagios.configtest
egrep -i "(^warning|^error)" "$TMPFILE" >> /var/run/nagios.configtest
chmod 0644 /var/run/nagios.configtest
cat "$TMPFILE"
exit 8
fi
}
start() {
test -x $exec || exit 5
test -f $config || exit 6
if test "$checkconfig" = "false"; then
check_config
fi
echo -n $"Starting $prog: "
# We need to _make sure_ the precache is there and verified
# Raise priority to make it run better
daemon --user=$user -- $exec -d $config
#touch $lockfile
retval=$?
echo
test $retval -eq 0 && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} $exec
retval=$?
echo
test $retval -eq 0 && rm -f $lockfile
return $retval
}
restart() {
check_config
checkconfig="true"
stop
start
}
reload() {
echo -n $"Reloading $prog: "
killproc -p ${pidfile} $exec -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
case "$1" in
start)
status_of_proc $prog && exit 0
$1
;;
stop)
status_of_proc $prog|| exit 0
$1
;;
restart)
$1
;;
reload)
status_of_proc $prog || exit 7
$1
;;
force-reload)
force_reload
;;
status)
status_of_proc $prog
;;
condrestart|try-restart)
status_of_proc $prog|| exit 0
restart
;;
configtest)
$nice su -s /bin/bash - nagios -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config"
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
exit $?
Re: Upgrading from 3.5.1 to 4.0.0
Posted: Fri Sep 27, 2013 11:06 am
by mlong
lmiltchev wrote:Here you go... Let us know if it worked for you.
Code: Select all
#!/bin/sh
# Nagios Startup script for the Nagios monitoring daemon
#
# chkconfig: - 85 15
# description: Nagios is a service monitoring system
# processname: nagios
# config: /etc/nagios/nagios.cfg
# pidfile: /var/nagios/nagios.pid
#
### BEGIN INIT INFO
# Provides: nagios
# Required-Start: $local_fs $syslog $network
# Required-Stop: $local_fs $syslog $network
# Short-Description: start and stop Nagios monitoring server
# Description: Nagios is is a service monitoring system
### END INIT INFO
# Source function library.
# . /etc/rc.d/init.d/functions
. /lib/lsb/init-functions
prefix="/usr/local/nagios"
exec_prefix="${prefix}"
exec="${exec_prefix}/bin/nagios"
prog="nagios"
config="${prefix}/etc/nagios.cfg"
pidfile="${prefix}/var/nagios.lock"
user="nagios"
group="nagios"
checkconfig="false"
ramdiskdir="/var/nagios/ramcache"
test -e /etc/sysconfig/$prog && . /etc/sysconfig/$prog
lockfile=/var/lock/$prog
USE_RAMDISK=${USE_RAMDISK:-0}
if test "$USE_RAMDISK" -ne 0 && test "$RAMDISK_SIZE"X != "X"; then
ramdisk=`mount |grep "$ramdiskdir type tmpfs"`
if [ "$ramdisk"X == "X" ]; then
mkdir -p -m 0755 $ramdiskdir
mount -t tmpfs -o size=${RAMDISK_SIZE}m tmpfs $ramdiskdir
mkdir -p -m 0755 $ramdiskdir/checkresults
chown -R $user:$group $ramdiskdir
fi
fi
check_config() {
TMPFILE="/tmp/.configtest.$$"
/usr/sbin/service nagios configtest > "$TMPFILE"
WARN=`grep ^"Total Warnings:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g`
ERR=`grep ^"Total Errors:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g`
if test "$WARN" = "0" && test "${ERR}" = "0"; then
echo "OK - Configuration check verified" > /var/run/nagios.configtest
chmod 0644 /var/run/nagios.configtest
/bin/rm "$TMPFILE"
return 0
else
# We'll write out the errors to a file we can have a
# script watching for
echo "WARNING: Errors in config files - see log for details: $TMPFILE" > /var/run/nagios.configtest
egrep -i "(^warning|^error)" "$TMPFILE" >> /var/run/nagios.configtest
chmod 0644 /var/run/nagios.configtest
cat "$TMPFILE"
exit 8
fi
}
start() {
test -x $exec || exit 5
test -f $config || exit 6
if test "$checkconfig" = "false"; then
check_config
fi
echo -n $"Starting $prog: "
# We need to _make sure_ the precache is there and verified
# Raise priority to make it run better
daemon --user=$user -- $exec -d $config
#touch $lockfile
retval=$?
echo
test $retval -eq 0 && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} $exec
retval=$?
echo
test $retval -eq 0 && rm -f $lockfile
return $retval
}
restart() {
check_config
checkconfig="true"
stop
start
}
reload() {
echo -n $"Reloading $prog: "
killproc -p ${pidfile} $exec -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
case "$1" in
start)
status_of_proc $prog && exit 0
$1
;;
stop)
status_of_proc $prog|| exit 0
$1
;;
restart)
$1
;;
reload)
status_of_proc $prog || exit 7
$1
;;
force-reload)
force_reload
;;
status)
status_of_proc $prog
;;
condrestart|try-restart)
status_of_proc $prog|| exit 0
restart
;;
configtest)
$nice su -s /bin/bash - nagios -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config"
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
exit $?
I replaced the /etc/init.d/nagios file with the reccomeded updated and when I attempted to restart nagios I received this
Code: Select all
root@nagios downloads/nagios# /etc/init.d/nagios restart
$Stopping nagios:
$Starting nagios: /etc/init.d/nagios: 149: daemon: not found
Re: Upgrading from 3.5.1 to 4.0.0
Posted: Fri Sep 27, 2013 11:13 am
by abrist
And this is on the debian squeeze box?
Re: Upgrading from 3.5.1 to 4.0.0
Posted: Fri Sep 27, 2013 11:26 am
by mlong
abrist wrote:And this is on the debian squeeze box?
Yep
and I have to say Turnkey Restore points are awesome
Re: Upgrading from 3.5.1 to 4.0.0
Posted: Fri Sep 27, 2013 11:49 am
by lmiltchev
Re: Upgrading from 3.5.1 to 4.0.0
Posted: Sat Sep 28, 2013 11:28 am
by mlong
lmiltchev wrote:Try running:
so after using the recommended init script and installing daemon (apt-get install daemon), I restarted the nagios process an everything looked good.
Code: Select all
root@nagios downloads/nagios# /etc/init.d/nagios restart
$Stopping nagios:
$Starting nagios:
Until I went to look at the Nagios web interface. it looked like the Nagios service was not running (see attachmet whoops.png)
I checked the status and got this
Code: Select all
root@nagios downloads/nagios# service nagios status
is not running ... failed!
THis time I manually stopped an started the service using
Code: Select all
root@nagios downloads/nagios# /etc/init.d/nagios stop
is not running ... failed!
root@nagios downloads/nagios# /etc/init.d/nagios start
is not running ... failed!
$Starting nagios:
This time nagios was actually running and I could see my Service status
When I rebooted I saw this:
Code: Select all
is not running ... failed!
$Starting nagios:
but when it was back up and running. Nagios seems to be working as expected.
Its kind of ugly, but it seems to have solved my issues.