I am developing an EventHandler to restart apache tomcat.
I have a shell script on the host tomcat is run from, that restarts tomcat. This script functions perfectly when executed by the nagios user on this host.
Code: Select all
#!/bin/bash
# /usr/local/nagios/libexec/eventhandlers/restart_tomcat1
#
# SCRIPT TO RESTART TOMCAT CALLED BY NRPE if check_http returns 2 soft Critical Results
/usr/bin/sudo /etc/init.d/tomcat1 stop
logger "TOMCAT1 - AUTO RESTART ATTEMPTED - STOP"
sleep 15
logger "TOMCAT1 - AUTO RESTART ATTEMPTED - WAIT 15sec"
/usr/bin/sudo /etc/init.d/tomcat1 start
logger "TOMCAT1 - AUTO RESTART ATTEMPTED - START"
echo "RESTART ATTEMPT FINISHED"
exit 0
HOWEVER if I execute the command via NRPE from my nagios server... It Fails.
The script executes and the Logger statments are printed, but nothing happens to the tomcat instance.
My Config is:
I have NRPE configured to accept the command: restartTomcat1
Code: Select all
command[restartTomcat1]=/usr/local/nagios/libexec/eventhandlers/restart_tomcat1
Code: Select all
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 NAGIOSHOST
}
Code: Select all
/usr/local/nagios/libexec/check_nrpe -H MyHOSTAddress -c restartTomcat1 -t 55
I have added the nagios user to the sudoers file
Code: Select all
nagios ALL=(ALL) NOPASSWD:ALL