Exim4+CentOS5 mail spool/queue on a ramdisk
After finishing my Exim 4.75 build from source (I needed to build in RADIUSclient support) I decided I wanted to try something crazy – Exim email queuing on a (volatile)ramdisk. I have seen this done on sendmail, but not on Exim. As it turns out, it wasn’t terribly hard, although I’m sure my solution for maintaining the queues integrity across reboots & service starts/stops could be much more eloquent.
In short, I made a 2g ramdisk and mounted it as /ram, made a back-up of /var/spool/exim as /var/spool/exim.bak and then moved /var/spool/exim to /ram/exim. I then symlinked /var/spool/exim -> /ram/exim.
mount -t tmpfs -o size=2g none /ram
cd /var/spool/
cp -r -p exim exim.bak
mv exim /ram/exim
ln -s /ram/exim exim
Then, I just modded up the exim start script. When ‘start’ is passed, I first check if the /ram mount point exists. If it does, I check to make sure the exim directory exists under it and if not, copy /var/spool/exim.bak to /ram/exim. If the mount point doesn’t exist, mount it, and then copy exim.bak /ram/exim.
start() {
# Start daemons.
if /bin/mount | grep "on /ram type" >/dev/null; then
if [ ! -e /ram/exim ]; then
/bin/cp -r -p /var/spool/exim.bak /ram/exim
fi
else
/bin/mount -t tmpfs -o size=2g none /ram
/bin/cp -r -p /var/spool/exim.bak /ram/exim
fi
echo -n "Starting exim: "
rm -f /var/spool/exim/db/*.lockfile 2>/dev/null
daemon /usr/sbin/exim $([ "$DAEMON" = yes ] && echo -bd) \
$([ -n "$QUEUE" ] && echo -q$QUEUE)
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/exim
}
Then, if ‘stop’ is passed to the script, first I check to make sure the /ram/exim directory exists. If it does, then I nuke /var/spool/exim.bak, and replace it with /ram/exim.
stop() {
# Stop daemons.
if [ -e /ram/exim ]; then
/bin/rm -rf /var/spool/exim.bak
/bin/cp -r -p /ram/exim /var/spool/exim.bak
fi
echo -n "Shutting down exim: "
killproc exim
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/exim
}
Getting around 2GB/s writes to /ram with dd tests, and crazy read times I’m sure (haven’t really measured yet).
We’ll see how it does under the load of a few thousand spammy lusers. I’ll report back and let you know, if I think of it.