220 lines
4.7 KiB
Bash
220 lines
4.7 KiB
Bash
#!/bin/sh
|
||
#
|
||
# Copyright (C) 2001-2007 Graeme Walker <graeme_walker@users.sourceforge.net>
|
||
#
|
||
# This program is free software; you can redistribute it and/or
|
||
# modify it under the terms of the GNU General Public License
|
||
# as published by the Free Software Foundation; either
|
||
# version 2 of the License, or (at your option) any later
|
||
# version.
|
||
#
|
||
# This program is distributed in the hope that it will be useful,
|
||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
# GNU General Public License for more details.
|
||
#
|
||
# You should have received a copy of the GNU General Public License
|
||
# along with this program; if not, write to the Free Software
|
||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||
#
|
||
# ===
|
||
#
|
||
# emailrelay-soak.sh
|
||
#
|
||
# Soak tests the E-MailRelay system to check for large
|
||
# memory leaks.
|
||
#
|
||
# It starts two servers, with a proxy fronting onto one
|
||
# of them, then in a loop it creates a large message file
|
||
# and runs a client to fowrard it to both servers in
|
||
# turn.
|
||
#
|
||
# Use 'ps' to check for large leaks.
|
||
#
|
||
# Files are created under a sub-directory of /tmp.
|
||
#
|
||
# usage: emailrelay-soak.sh [<exe>]
|
||
#
|
||
# (As a side-effect it does "killall emailrelay".)
|
||
#
|
||
|
||
# configuration
|
||
#
|
||
exe="`dirname $0`/../src/main/emailrelay"
|
||
test -z "${1}" || exe="${1}"
|
||
content="/etc/services"
|
||
pp="1001" # port prefix
|
||
|
||
# configuration fallback
|
||
#
|
||
bin_dir="`dirname $0`"
|
||
if test \! -f "${exe}" -a -x "${bin_dir}/../emailrelay"
|
||
then
|
||
exe="${bin_dir}/../emailrelay"
|
||
echo `basename $0`: using executable \"${exe}\" >&2
|
||
fi
|
||
|
||
# initialisation
|
||
#
|
||
as_client="--no-syslog --no-daemon --dont-serve --forward --forward-to" # no --log
|
||
as_server="--log" # no --close-stderr
|
||
as_proxy="--log --immediate --forward-to" # no --close-stderr
|
||
base_dir="/tmp/`basename $0`.$$.tmp"
|
||
auth_file="${base_dir}/`basename $0 .sh`.auth"
|
||
mkdir "${base_dir}"
|
||
trap "rm -rf ${base_dir} 2>/dev/null ; killall emailrelay 2>/dev/null ; exit" 0 1 2 3 13 15
|
||
|
||
Auth()
|
||
{
|
||
echo "login server joe joe+00s+3Dpassword"
|
||
echo "login client joe joe+00s+3Dpassword"
|
||
}
|
||
|
||
Content()
|
||
{
|
||
echo "To:" ${USER}@`uname -n`
|
||
echo "Subject: test message from process" $$
|
||
echo "From: tester"
|
||
echo ""
|
||
for i in 1 1 1 1 1 1 1 1 1 1
|
||
do
|
||
cat "${content}"
|
||
done
|
||
}
|
||
|
||
Envelope()
|
||
{
|
||
echo "X-MailRelay-Format: #2821.3"
|
||
echo "X-MailRelay-Content: 8bit"
|
||
echo "X-MailRelay-From: me"
|
||
echo "X-MailRelay-ToCount: 1"
|
||
echo "X-MailRelay-To-Remote:" ${USER}@`uname -n`
|
||
echo "X-MailRelay-Authentication: anon"
|
||
echo "X-MailRelay-Client: 127.0.0.1"
|
||
echo "X-MailRelay-End: 1"
|
||
}
|
||
|
||
CrLf()
|
||
{
|
||
sed 's/$/<2F>/' | tr '<27>' '\r'
|
||
}
|
||
|
||
CreateMessage()
|
||
{
|
||
spool_dir="${1}"
|
||
|
||
Content | CrLf > ${spool_dir}/emailrelay.$$.1.content
|
||
Envelope | CrLf > ${spool_dir}/emailrelay.$$.1.envelope
|
||
}
|
||
|
||
RunClient()
|
||
{
|
||
to_address="${1}"
|
||
spool_dir="${2}"
|
||
|
||
${exe} ${as_client} ${to_address} --spool-dir ${spool_dir} --client-auth ${auth_file}
|
||
}
|
||
|
||
Send()
|
||
{
|
||
to_address="${1}"
|
||
|
||
dir="${base_dir}/spool-send"
|
||
mkdir -p "${dir}"
|
||
|
||
CreateMessage "${dir}"
|
||
RunClient "${to_address}" "${dir}"
|
||
}
|
||
|
||
RunServer()
|
||
{
|
||
port="${1}"
|
||
spool_dir="${2}"
|
||
log="${3}"
|
||
pid_file="${4}"
|
||
|
||
if test "`echo ${pid_file} | grep '^/'`" = ""
|
||
then
|
||
pid_file="`pwd`/${pid_file}"
|
||
fi
|
||
|
||
mkdir -p "${spool_dir}"
|
||
set -x
|
||
${exe} ${as_server} --port ${port} --spool-dir ${spool_dir} \
|
||
--pid-file ${pid_file} \
|
||
--server-auth ${auth_file} \
|
||
--admin `expr ${port} + 100` --forward-to localhost:smtp --no-syslog 2> "${log}"
|
||
set +x
|
||
}
|
||
|
||
RunProxy()
|
||
{
|
||
port="${1}"
|
||
to_address="${2}"
|
||
spool_dir="${3}"
|
||
log="${4}"
|
||
pid_file="${5}"
|
||
|
||
if test "`echo ${pid_file} | grep '^/'`" = ""
|
||
then
|
||
pid_file="`pwd`/${pid_file}"
|
||
fi
|
||
|
||
mkdir -p "${spool_dir}"
|
||
set -x
|
||
${exe} ${as_proxy} ${to_address} --port ${port} --spool-dir ${spool_dir} \
|
||
--pid-file ${pid_file} \
|
||
--server-auth ${auth_file} \
|
||
--client-auth ${auth_file} \
|
||
--admin `expr ${port} + 100` --no-syslog 2> "${log}"
|
||
set +x
|
||
}
|
||
|
||
Init()
|
||
{
|
||
killall emailrelay 2>/dev/null
|
||
Auth > ${auth_file}
|
||
}
|
||
|
||
RunServers()
|
||
{
|
||
RunServer ${pp}3 ${base_dir}/spool-3 server-2.out server-2.pid
|
||
RunProxy ${pp}1 localhost:${pp}3 ${base_dir}/spool-1 proxy.out proxy.pid
|
||
RunServer ${pp}2 ${base_dir}/spool-2 server-1.out server-1.pid
|
||
sleep 1 # to allow pid files time to be written
|
||
}
|
||
|
||
CheckServers()
|
||
{
|
||
if test \! -f server-1.pid -o \! -f server-2.pid -o \! -f proxy.pid
|
||
then
|
||
echo `basename $0`: error starting 'server(s)' >&2
|
||
cat server-?.out proxy.out 2>/dev/null | sed 's/^/ /' >&2
|
||
exit 1
|
||
fi
|
||
}
|
||
|
||
Ps()
|
||
{
|
||
echo `basename $0`: output from \"ps -l -p `cat server-2.pid` -p `cat server-1.pid` -p `cat proxy.pid`\"...
|
||
ps -l -p `cat server-2.pid` -p `cat server-1.pid` -p `cat proxy.pid` | sed 's/^/ /'
|
||
}
|
||
|
||
Main()
|
||
{
|
||
while true
|
||
do
|
||
Send localhost:${pp}1
|
||
Send localhost:${pp}2
|
||
echo -n .
|
||
rm -f ${base_dir}/spool-?/*content
|
||
done
|
||
}
|
||
|
||
Init
|
||
RunServers
|
||
CheckServers
|
||
Ps
|
||
Main
|
||
|