[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Help: slapd respawning too fast



Martin Strohbach wrote:

> Am Don, 29 Jun 2000 schrieb Randy Kunkee:
> > > Hello!
> > >
> > > I use OpenLdap 1.2 and SuSE Linux.
> > > Im my inittab I have added the entry
> > >     ld:23:respawn:/usr/local/libexec/slapd -f /usr/local/etc/openldap/myslapd.conf
> > >
> > > But something goes wrong: init always wants to restart slapd although it
> > > is already running:
> > >
> > > slapd[22306]: slapd starting
> > > slapd[22311]: bind() failed errno 98 (Address already in use)
> > > slapd[22312]: bind() failed errno 98 (Address already in use)
> > > slapd[22316]: bind() failed errno 98 (Address already in use)
> > > slapd[22324]: bind() failed errno 98 (Address already in use)
> > > slapd[22322]: bind() failed errno 98 (Address already in use)
> > > init: Id "ld" respawning too fast: disabled for 5 minutes
> > > slapd[22328]: bind() failed errno 98 (Address already in use)
> > > slapd[22333]: bind() failed errno 98 (Address already in use)
> > > slapd[22335]: bind() failed errno 98 (Address already in use)
> > > slapd[22337]: bind() failed errno 98 (Address already in use)
> > >
> > > Thanks for any help
> > >
> >
> > This is really a Unix system admin problem, and has very little to do
> > with OpenLDAP at all except that the way you are running it, slapd puts
> > itself in the background, and appears to init to exit, thus the attempts
> > to restart it.  Eventually init disarms itself.
> >
> > Running slapd out of init is not necessarily the right thing to do, but
> > if you want to do it, you need to use a flag to support slapd's backgrounding
> > of itself.  Check the manpage.  I believe you can use -d 0 to accomplish
> > this.
>
> -d 0 does not work. I added -d 1 that worked. Well, it's right I don't have to
> start slapd necassariliy out of init - I have no Problems with the stability of
> slapd. But if I really want to go sure that slapd is automatically restarted,
> I think then I should use init. Okay, I could use a script checking if slapd is
> still alive ...

Below the cheeseball script that I whipped up to do this sort of thing (use at your own
risk, etc.):

You'd use it like this:

daemonwatch 20 /var/run/slapd.pid /usr/local/libexec/slapd >/dev/null 2>&1 &

So then every 20 seconds it checks to see if its running...if it's not it tries to restart
it... if this fails it tries again, but starts waiting longer and longer between each
attempt.  It does some syslog logging as well...


#!/bin/sh

# syntax:    daemonwatch delayseconds pidfile cmd [args...]

minwait=4
maxwait=3600

usage='syntax:    daemonwatch delayseconds pidfile cmd [args...]'

if [ $# -lt 3 ]; then
        echo $usage
        echo
        exit 1
fi

waittime=$1
realwait=$waittime
pidfile=$2
shift 2

if [ ! \( -r $1 -a -e $1 \) ]; then
        echo $1 is not executable
        exit 1
fi

test $waittime -gt $minwait 2>/dev/null
if [ $? -ne 0 ]; then
        echo $usage
        echo "    delayseconds must be a number greater than $minwait"
        echo
        exit 1
fi

first=1
seenerr=0

while true ; do
        if [ $first -eq 1 ]; then
                verb="initial launch of"
                       first=0
        else
                verb="restarted"
        fi
        [ -f $pidfile ] && ( ps ax | grep -v grep | grep -q `cat $pidfile` )
        if [ $? -ne 0 ]; then
                $*
                err=$?
                if [ $err -ne 0 ]; then
                        # if not first error
                        if [ $seenerr -gt 0 ]; then
                                # Ramp waittime up
                                if [ $realwait -le $maxwait ]; then
                                        realwait=`expr $realwait \* 2`
                                fi
                                result=", WITH ERROR!  Exit code: $err  REPEAT #$seenerr"
                                seenerr=`expr $seenerr + 1`
                        else
                                # at first error event, set new log text
                                result=", WITH ERROR!  Exit code: $err"
                                seenerr=1
                        fi
                else
                        sleep 1
                        [ -f $pidfile ] && result=", new pid: "`cat $pidfile`
                        seenerr=0
                        realwait=$waittime
                fi
                logger "daemonwatch:  $verb $1""$result"
        fi

        sleep $realwait
done

--
-------------------------------------------------------------------------
  Charles N. Owens                               Email: owensc@enc.edu
                                            http://www.enc.edu/~owensc
  Network & Systems Administrator
  Information Technology Services  "Outside of a dog, a book is a man's
  Eastern Nazarene College         best friend.  Inside of a dog it's
                                   too dark to read." - Groucho Marx
-------------------------------------------------------------------------