How to restart service?


#1

I have Nagios monitoring a couple Linux Groupwise services with the following script:

if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE is running"
exit 0
else
echo "$SERVICE is not running"
exit 2
fi

This works grwat however how could I make it execute the /etc/init.d/grpwise start if the service is not running? I tried adding the line like this:

if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE is running"
exit 0
else
/etc/init.d/grpwise start
sleep 5
echo "$SERVICE is not running"
exit 2
fi

The above works from a terminal but does not work when Nagios tries to execute it. Any ideas?


#2

I think it has to do with the permissions but I am not sure how to allow the user nagios to execute the command.