aboutsummaryrefslogtreecommitdiff
path: root/mail/MailScanner-devel/files/mta.sh
blob: 7bce65f9d8d86ab8c9b49830bd106953f1386a68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh

outgoing_queue_time=15m
mta=exim

case "$mta" in
	exim)
		program=/usr/local/sbin/exim

		if [ -f /usr/local/etc/exim/configure.in ]; then
			incoming_config=/usr/local/etc/exim/configure.in
		else
			incoming_config=/usr/local/etc/exim/configure
		fi

		outgoing_config=/usr/local/etc/exim/configure.out

		inpidfile=/var/run/exim_in.pid
		outpidfile=/var/run/exim_out.pid
		subpidfile=

		incoming_args="-C ${incoming_config} -oP ${inpidfile} -bd"
		outgoing_args="-C ${outgoing_config} -oP ${outpidfile} -q${outgoing_queue_time}"
		submitqueue_args=
		;;

	sendmail)
		program=/usr/sbin/sendmail

		incoming_queue=/var/spool/mqueue.in

		submit_queue_time=${outgoing_queue_time}

		inpidfile=/var/run/sendmail_in.pid
		outpidfile=/var/run/sendmail_out.pid
		subpidfile=/var/spool/clientmqueue/sm-client.pid

		incoming_args="-L sm-mta-in -bd \
				-OPrivacyOptions=noetrn \
				-OQueueDirectory=${incoming_queue} \
				-ODeliveryMode=queueonly \
				-OPidFile=${inpidfile}"
		outgoing_args="-L sm-mta-out -q${outgoing_queue_time} \
				-OPidFile=${outpidfile}"
		submitqueue_args="-L sm-msp-queue -Ac -q${submit_queue_time} \
				-OPidFile=${subpidfile}"
		;;

	*)
		echo "ERROR: I don't know the MTA '$mta'. Check your settings." >&2
		exit 2
		;;
esac

start_mta()
{
	echo -n " `basename ${program}`(incoming)"
	${program} ${incoming_args}

	echo -n " `basename ${program}`(outgoing)"
	${program} ${outgoing_args}
}

start_mspq ()
{
	if [ "${submitqueue_args}" ]; then
		echo -n " `basename ${program}`(submitqueue)"
		${program} ${submitqueue_args}
	fi
}

stop_mta()
{
	echo "Stopping `basename ${program}` (incoming)"
	kill -TERM `head -1 ${inpidfile}` 2>/dev/null

	echo "Stopping `basename ${program}` (outgoing)"
	kill -TERM `head -1 ${outpidfile}` 2>/dev/null
}

stop_mspq ()
{
	if [ "${submitqueue_args}" ]; then
		echo "Stopping `basename ${program}` (submitqueue)"
		kill -TERM `head -1 ${subpidfile}` 2>/dev/null
	fi
}


_action=${1:-start}

case ${_action} in
start)
        start_mta
	start_mspq
        ;;

stop)
        stop_mta
	stop_mspq
        ;;

restart)
	stop_mta
	stop_mspq
	sleep 5
	start_mta
	start_mspq
	;;

*)
	echo "Usage: `basename $0` {start|stop|restart}" >&2
	exit 64
	;;
esac
exit 0