xref: /dragonfly/etc/rc.d/sendmail (revision 4e7eb5cc)
1#!/bin/sh
2#
3# $NetBSD: sendmail,v 1.14 2002/02/12 01:26:36 lukem Exp $
4# $FreeBSD: src/etc/rc.d/sendmail,v 1.7 2002/10/12 10:31:31 schweikh Exp $
5# $DragonFly: src/etc/rc.d/sendmail,v 1.2 2003/11/19 10:32:45 eirikn Exp $
6#
7
8# PROVIDE: mail
9# REQUIRE: LOGIN
10# KEYWORD: DragonFly FreeBSD NetBSD
11#	we make mail start late, so that things like .forward's are not
12#	processed until the system is fully operational
13
14# XXX - Get together with sendmail mantainer to figure out how to
15#	better handle SENDMAIL_ENABLE and 3rd party MTAs.
16#
17. /etc/rc.subr
18
19name="sendmail"
20rcvar=`set_rcvar`
21required_files="/etc/mail/${name}.cf"
22
23case ${OSTYPE} in
24DragonFly)
25	command=${sendmail_program:-/usr/sbin/sendmail}
26	pidfile=${sendmail_pidfile:-/var/run/sendmail.pid}
27	load_rc_config $name
28	case ${sendmail_enable} in
29	[Nn][Oo][Nn][Ee])
30		sendmail_enable="NO"
31		sendmail_submit_enable="NO"
32		sendmail_outbound_enable="NO"
33		sendmail_msp_queue_enable="NO"
34		;;
35	esac
36	;;
37FreeBSD)
38	command=${sendmail_program:-/usr/sbin/sendmail}
39	pidfile=${sendmail_pidfile:-/var/run/sendmail.pid}
40
41	load_rc_config $name
42
43	case ${sendmail_enable} in
44	[Nn][Oo][Nn][Ee])
45		sendmail_enable="NO"
46		sendmail_submit_enable="NO"
47		sendmail_outbound_enable="NO"
48		sendmail_msp_queue_enable="NO"
49		;;
50	esac
51	;;
52NetBSD)
53	command="/usr/sbin/${name}"
54	pidfile="/var/run/${name}.pid"
55	start_precmd="sendmail_precmd"
56
57	load_rc_config $name
58	;;
59esac
60
61sendmail_precmd()
62{
63	# Die if there's pre-8.10 custom configuration file.  This check is
64	# mandatory for smooth upgrade.  See NetBSD PR 10100 for details.
65	#
66	if checkyesno ${rcvar} && [ -f "/etc/${name}.cf" ]; then
67		if ! cmp -s "/etc/mail/${name}.cf" "/etc/${name}.cf"; then
68			warn \
69    "${name} was not started; you have multiple copies of sendmail.cf."
70			return 1
71		fi
72	fi
73
74	# check modifications on /etc/mail/aliases
75	if [ -f "/etc/mail/aliases.db" ]; then
76		if [ "/etc/mail/aliases" -nt "/etc/mail/aliases.db" ]; then
77			echo \
78	    "${name}: /etc/mail/aliases newer than /etc/mail/aliases.db, regenerating"
79			/usr/bin/newaliases
80		fi
81	else
82		echo \
83	    "${name}: /etc/mail/aliases.db not present, generating"
84			/usr/bin/newaliases
85	fi
86
87	# check couple of common db files, too
88	for f in genericstable virtusertable domaintable mailertable; do
89		if [ -r "/etc/mail/$f" -a \
90		    "/etc/mail/$f" -nt "/etc/mail/$f.db" ]; then
91			echo \
92    "${name}: /etc/mail/$f newer than /etc/mail/$f.db, regenerating"
93			/usr/sbin/makemap hash /etc/mail/$f < /etc/mail/$f
94		fi
95	done
96}
97
98run_rc_command "$1"
99
100case ${OSTYPE} in
101DragonFly)
102	required_files=
103	if ! checkyesno sendmail_enable; then
104		name="sendmail_submit"
105		rcvar=`set_rcvar`
106		start_cmd="${command} ${sendmail_submit_flags}"
107		run_rc_command "$1"
108	fi
109	if ! checkyesno sendmail_outbound_enable; then
110		name="sendmail_outbound"
111		rcvar=`set_rcvar`
112		start_cmd="${command} ${sendmail_outbound_flags}"
113		run_rc_command "$1"
114	fi
115	name="sendmail_clientmqueue"
116	rcvar="sendmail_msp_queue_enable"
117	start_cmd="${command} ${sendmail_msp_queue_flags}"
118	pidfile="${sendmail_mspq_pidfile:-/var/spool/clientmqueue/sm-client.pid}"
119	required_files="/etc/mail/submit.cf"
120	run_rc_command "$1"
121	;;
122FreeBSD)
123	required_files=
124
125	if ! checkyesno sendmail_enable; then
126		name="sendmail_submit"
127		rcvar=`set_rcvar`
128		start_cmd="${command} ${sendmail_submit_flags}"
129		run_rc_command "$1"
130	fi
131
132	if ! checkyesno sendmail_outbound_enable; then
133		name="sendmail_outbound"
134		rcvar=`set_rcvar`
135		start_cmd="${command} ${sendmail_outbound_flags}"
136		run_rc_command "$1"
137	fi
138
139	name="sendmail_clientmqueue"
140	rcvar="sendmail_msp_queue_enable"
141	start_cmd="${command} ${sendmail_msp_queue_flags}"
142	pidfile="${sendmail_mspq_pidfile:-/var/spool/clientmqueue/sm-client.pid}"
143	required_files="/etc/mail/submit.cf"
144	run_rc_command "$1"
145	;;
146esac
147