Init.d script failing to stop service on RedHat
The other day I had an irritating issue with an init script on RedHat. I had enabled the script using chkconfig command. The service would start up just fine, but when the server was bounced, the script was skipped and stop operation was not performed.
I had checked all the symlinks in rc.* directories and everything seemed fine. Despite that script’s stop was not called during reboot/shutdown.
So I took a look at /etc/rc.d/rc script since it is responsible for handling init scripts when runlevel change occurs. And I came across following section:
# First, run the KILL scripts.
for i in /etc/rc$runlevel.d/K* ; do
check_runlevel "$i" || continue
# Check if the subsystem is already up.
subsys=${i#/etc/rc$runlevel.d/K??}
[ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] \
|| continue
# Bring the subsystem down.
if LC_ALL=C egrep -q "^..*init.d/functions" $i ; then
$i stop
else
action $"Stopping $subsys: " $i stop
fi
done
The code checked for presence of /var/lock/subsys/
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/crond;
return $RETVAL
That had fixed the issue.