pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: clamsmtpd started too early (pkg/36292)



On Tue, May 29, 2007 at 12:12:25PM +0300, Martti Kuparinen wrote:
> 
> As the new maintainer for clamsmtpd, I started to look at (my own)
> pkg/36292. I'm running now the following patch on my servers and all
> problems are gone.
> 
> Any objection for this change? Is it okay to use expr?

I see your changes have already gone in.  It's safe to use expr because
by the time LOGIN happens, /usr should already have been mounted.
Plus, I mean, we're already using /usr/bin/awk earlier in the script.

> PS. On my secondary MX host it takes over 40 seconds for clamd to start.
>     This is a 2.8 GHz P4 with 2 GB RAM and only DNS and SMTP services
>     running...
> 
> Martti
> 
> 
> 
> --- /var/tmp/clamsmtpd        2007-05-29 10:46:13.000000000 +0300
> +++ /etc/rc.d/clamsmtpd       2007-05-29 11:27:16.000000000 +0300
> @@ -39,11 +39,34 @@
>                       /^#/ {next}; /^User[    ]/ {r = $2};
>                       END {print r}' ${clamav_conffile}`}
>  else
> +     : ${socket="/tmp/clamd"}
>       : ${clamsmtpd_user="clamav"}
>  fi
> 
>  clamsmtpd_prestart()
>  {
> +     if [ ! -S "${socket}" ]; then
> +             # Max wait time is 2 minutes
> +             retries=11
> +
> +             echo -n "Waiting for clamd to become ready"
> +             while [ ${retries} -gt 0 -a ! -S "${socket}" ]; do
> +                     echo -n "."
> +                     sleep 10
> +                     retries=`expr ${retries} - 1`
> +                     slow=true
> +             done
> +             if [ ! -S "${socket}" ]; then
> +                     echo ""
> +                     echo "ERROR: Unable to start clamsmtpd as clamd is 
> not running!"
> +                     exit 1
> +             fi
> +
> +             # Wait another 10 seconds so that clamd is really ready
> +             echo -n "."
> +             sleep 10
> +             echo ""
> +     fi
>       /usr/bin/touch ${pidfile}
>       /usr/sbin/chown ${clamsmtpd_user} ${pidfile}
>  }

If you're really worried about script portability, or not using $((...)),
you could always write the loop as:

        # Max wait time is 2 minutes.
        echo -n "Waiting for clamd to become ready"
        for dummy in 1 2 3 4 5 6 7 8 9 10 11; do
                # Poll for presence of clamd's socket in 10-second blocks.
                if [ -S "${socket}" ]; then
                        # Wait 10 more seconds for clamd to settle.
                        echo -n "."
                        sleep 10
                        break
                fi
                echo -n "."
                sleep 10
        done
        echo ""
        if [ ! -S "${socket}" ]; then
                echo "ERROR: Unable to start clamsmtpd as clamd is not running!"
                exit 1
        fi

Also, given that we now pretty much assume the use of NetBSD's rc.d
system, you can remove the extra checks and guards for the non-rc.d
case within that script.

        Cheers,

        -- Johnny Lam <jlam%pkgsrc.org@localhost>



Home | Main Index | Thread Index | Old Index