On Wed, May 25, 2005 at 11:26:03PM +0800, Eugene Konev wrote:

>  On Mon, 23 May 2005 17:11:44 +0200
>  you wrote:

>  TL> Looks like we should do that after bazillions of people requested it.
>  TL> Any suggestions how to implement this correctly?

> The attached patch adds calling db4.2_recover to slapd.init on every
> slapd startup.

Are there any objections to applying this patch for sarge?

-- 
Steve Langasek
postmodern programmer

> diff -Nru openldap2.2-2.2.23/debian/slapd.init 
> openldap2.2-hack/debian/slapd.init
> --- openldap2.2-2.2.23/debian/slapd.init      2005-05-24 19:42:21.000000000 
> +0800
> +++ openldap2.2-hack/debian/slapd.init        2005-05-25 23:15:35.000000000 
> +0800
> @@ -48,6 +48,10 @@
>               "$SLAPD_CONF"`
>  fi
>  
> +# Find out slapd db directories
> +SLAPD_DBDIRS=`sed -ne 's/^directory[[:space:]]\+"*\([^"]\+\).*/\1/p' \
> +                "$SLAPD_CONF" `
> +     
>  # XXX: Breaks upgrading if there is no pidfile (invoke-rc.d stop will fail)
>  # -- Torsten
>  if [ -z "$SLAPD_PIDFILE" ]; then
> @@ -107,6 +111,24 @@
>  }
>  
>  
> +# Try to recover slapd database
> +try_fix_db() {
> +     if [ "$SLAPD_TRYFIXDB" != yes -o \
> +           -z "$SLAPD_DBDIRS" ]; then
> +             return 0
> +     fi
> +     echo -n " (possibly) fixing db,"
> +     for DBDIR in $SLAPD_DBDIRS; do
> +         if [ -d "$DBDIR" -a -f "$DBDIR/objectClass.bdb" ]; then
> +             db4.2_recover -eh $DBDIR 2>&1
> +             if [ $? -ne 0 ]; then
> +                 reason="Automatic recovery of slapd database failed. You 
> will need to perform recovery by hand, possibly from backup."
> +                 exit 1
> +             fi
> +         fi
> +     done
> +}
> +
>  # Start the slapd daemon and capture the error message if any to 
>  # $reason.
>  start_slapd() {
> @@ -157,6 +179,7 @@
>  start() {
>       echo -n "Starting OpenLDAP:"
>       trap 'report_failure' 0
> +     try_fix_db
>       start_slapd
>       start_slurpd
>       trap "-" 0

Attachment: signature.asc
Description: Digital signature

Reply via email to