summaryrefslogtreecommitdiff
blob: 6a9ebd192cb5a73c28009ba623762cdb8f511373 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/sbin/runscript
# Portions Copyright 2003 Gentoo Linux
# $Header: /var/cvsroot/gentoo-x86/mail-mta/courier/files/courier-init-r1,v 1.1 2006/07/11 00:21:53 chtekk Exp $
#
# script originally from Courier distfile original name = courier.sysvinit
# adapted for Gentoo by Brian Jackson
#
# TODO
# should we update all the .dat/.pem files when the source/config files are 
#	newer than the .dat/.pem files?

prefix="/usr"
exec_prefix="/usr/bin"
sysconfdir="/etc/courier"
sbindir="/usr/sbin"
libexecdir="/usr/lib/courier"
datadir="/usr/share/courier"

depend() {
	need net
	[ -d /etc/courier/authlib ] && need courier-authlib
	grep -q "^IMAPDSTART=.*[Yy].*" /etc/courier/imapd && use famd
	grep -q "^IMAPDSSLSTART=.*[Yy].*" /etc/courier/imapd-ssl && use famd
}

checkconfig() {

	[ -f ${sysconfdir}/pop3d-ssl ] && . ${sysconfdir}/pop3d-ssl

	# If we do not have a certificate, make one up.
	[ ! -f "${datadir}/pop3d.pem" ] && \
	ebegin " generating-POP3-SSL-certificate..." && "${sbindir}/mkpop3dcert"

	[ -f ${sysconfdir}/imapd-ssl ] && . ${sysconfdir}/imapd-ssl

	# If we do not have a certificate, make one up.
	[ ! -f ${datadir}/imapd.pem ] && \
	ebegin " generating-IMAP-SSL-certificate..." && "${sbindir}/mkimapdcert"

	[ -f ${sysconfdir}/esmtpd-ssl ] && . ${sysconfdir}/esmtpd-ssl

	# If we do not have a certificate, make one up.
	[ ! -f ${datadir}/esmtpd.pem ] && \
	ebegin " generating-ESMTP-SSL-certificate..." && "${sbindir}/mkesmtpdcert"

	# First time after install create aliases.dat and smtpaccess.dat

	[ -f ${sysconfdir}/aliases.dat ] || ${sbindir}/makealiases

	[ -f ${sysconfdir}/${ACCESSFILE}.dat ] || ${sbindir}/makesmtpaccess

	[ -f ${sysconfdir}/${ACCESSFILE}.dat ] || ${sbindir}/makesmtpaccess-msa
}

start() {
	# Start daemons.
	ebegin "Starting Courier mail server:"

	checkconfig || return 1

	ebegin " Starting courierfilterd"
	${sbindir}/courierfilter start

	[ ! -d /etc/courier/authlib ] && [ -x ${libexecdir}/authlib/authdaemond ] && \
	${libexecdir}/authlib/authdaemond start && ebegin " Starting authdaemond"

	[ -x ${libexecdir}/courier/webmaild ] && \
	  ${libexecdir}/courier/webmaild start && ebegin " Starting webmaild" 
	[ ! -x ${libexecdir}/courier/webmaild ] && [ -x ${libexecdir}/courier/sqwebmaild ] && \
	  ${libexecdir}/courier/sqwebmaild start && ebegin " Starting sqwebmaild"

	[ -x ${sbindir}/courierldapaliasd ] && \
	${sbindir}/courierldapaliasd start && ebegin " Starting courierldapaliasd"

	ebegin " Starting courierd"
	${sbindir}/courier start

	# start esmtpd if so written
	[ -f ${sysconfdir}/esmtpd ] && source ${sysconfdir}/esmtpd
	case x$ESMTPDSTART in
	x[yY]*)
		ebegin " Starting esmtpd"
		${sbindir}/esmtpd start
		;;
	esac

	# start esmtpd-msa if so written
	[ -f ${sysconfdir}/esmtpd-msa ] && source ${sysconfdir}/esmtpd-msa
	case x$ESMTPDSTART in
	x[yY]*)
		ebegin " Starting esmtpd-msa"
		${sbindir}/esmtpd-msa start
		;;
	esac

	# start esmtpd-ssl if so written
	[ -f ${sysconfdir}/esmtpd-ssl ] && source ${sysconfdir}/esmtpd-ssl
	case x$ESMTPDSSLSTART in
	x[yY]*)
		ebegin " Starting esmtpd-ssl"
		${sbindir}/esmtpd-ssl start
		;;
	esac

	# start pop3d if so written
	[ -f ${sysconfdir}/pop3d ] && source ${sysconfdir}/pop3d
	case x$POP3DSTART in
	x[yY]*)
		ebegin " courier-pop3d"
		${sbindir}/courier-pop3d start
		;;
	esac

	# start pop3d-ssl if so written
	[ -f ${sysconfdir}/pop3d-ssl ] && source ${sysconfdir}/pop3d-ssl
	case x$POP3DSSLSTART in
	x[yY]*)
		ebegin " courier-pop3d-ssl"
		${sbindir}/courier-pop3d-ssl start
		;;
	esac

	[ -f ${sysconfdir}/imapd ] && source ${sysconfdir}/imapd
	case x$IMAPDSTART in
	x[yY]*)
		ebegin " courier-imapd"
		${sbindir}/courier-imapd start
		;;
	esac

	[ -f ${sysconfdir}/imapd-ssl ] && source ${sysconfdir}/imapd-ssl
	case x$IMAPDSSLSTART in
	x[yY]*)
		ebegin " courier-imapd-ssl"
		${sbindir}/courier-imapd-ssl start
		;;
	esac

	eend $?
}

stop() {
	ebegin "Stopping Courier mail server:"

	ebegin " Stopping courier-esmtpd"
	${sbindir}/esmtpd stop

	ebegin " Stopping courier-esmtpd-msa"
	${sbindir}/esmtpd-msa stop

	ebegin " Stopping courier-esmtpd-ssl"
	${sbindir}/esmtpd-ssl stop

	[ -x ${sbindir}/courier-pop3d ] && \
		ebegin " Stopping courier-pop3d" && ${sbindir}/courier-pop3d stop

	[ -x ${sbindir}/courier-pop3d-ssl ] && \
		ebegin " Stopping courier-pop3d-ssl" && ${sbindir}/courier-pop3d-ssl stop

	[ -x ${sbindir}/courier-imapd ] && \
		ebegin " Stopping courier-imapd" && ${sbindir}/courier-imapd stop


	[ -x ${sbindir}/courier-imapd-ssl ] && \
		ebegin " Stopping courier-imapd-ssl" && ${sbindir}/courier-imapd-ssl stop

	ebegin " Stopping courierd"
	${sbindir}/courier stop

	[ -x ${sbindir}/courierldapaliasd ] && \
	( ${sbindir}/courierldapaliasd stop ; ebegin " Stopping courierldapaliasd" )

	[ -x ${libexecdir}/courier/webmaild ] && \
	  ( ${libexecdir}/courier/webmaild stop ; ebegin " Stopping webmaild" )
	[ ! -x ${libexecdir}/courier/webmaild ] && [ -x ${libexecdir}/courier/sqwebmaild ] && \
	  ( ${libexecdir}/courier/sqwebmaild stop ; ebegin " Stopping sqwebmaild" )

	[ ! -d /etc/courier/authlib ] && [ -x ${libexecdir}/authlib/authdaemond ] && \
	( ${libexecdir}/authlib/authdaemond stop ; ebegin " Stopping authdaemond" )

	${sbindir}/courierfilter stop
	ebegin " Stopping courierfilterd"

	eend $?
}