@!@
hostname = baseConfig['hostname']
domainname = baseConfig['domainname']
myfqdn = '.'.join([ hostname, domainname ])
isMurder = False
murders = baseConfig.get('mail/cyrus/murder/servers', "")
mail_cyrus_murder_master = baseConfig.get('mail/cyrus/murder/master')

if hostname + "$" in murders.split(" "):
	isMurder = True

pre = ''
interface = baseConfig.get('mail/cyrus/murder/frontend/interface')
if interface:
	ucrVariable = 'interfaces/' + interface + '/address'
	interfaceIP = baseConfig.get(ucrVariable)
	if interfaceIP:
		pre = "%s:" % interfaceIP

if mail_cyrus_murder_master:
	if mail_cyrus_murder_master == myfqdn:
		mupdateMaster = 1
		print ' '
		print '        # --- Mupdate master ---------------------------'
		print ''
		print '        # (mupdate master, only one in the entire cluster)'
		print '        # mupdate database service - must prefork at least 1'
		print '        mupdate cmd="mupdate -m -C /etc/imapd/master.conf" listen=3905 prefork=1'
		print ''
		print '        # ----------------------------------------------'
		print ''
	else:
		mupdateMaster = 0

	if isMurder and pre:
		print ''
		print '        # --- Murder frontends -------------------------'
		print ''
		print '        # (mupdate slaves) except for sieve (which deals automatically with Mupdate)'
		if not mupdateMaster:
			print '        # mupdate database service - must prefork at least 1'
			print '        mupdate cmd="mupdate -C /etc/imapd/frontend.conf" listen="3905" prefork=1'

		if baseConfig.get('mail/cyrus/imap') == 'yes' and pre:
			maxchild = baseConfig.get('mail/cyrus/imap/maxchilds', '400')
			print ''
			print '        # proxy imap/imaps'
			print '        imapproxy cmd="proxyd -C /etc/imapd/frontend.conf -U 30" listen="%simap" prefork=0 maxchild=%s' % (pre, maxchild)
			print '        imapsproxy cmd="proxyd -C /etc/imapd/frontend.conf -s -U 30" listen="%simaps" prefork=0 maxchild=%s' % (pre, maxchild)

		if baseConfig.get('mail/cyrus/pop') == 'yes' and pre:
			maxchild = baseConfig.get('mail/cyrus/pop/maxchilds', '400')
			print ''
			print '        # proxy pop/pops'
			print '        pop3proxy cmd="pop3proxyd -C /etc/imapd/frontend.conf -U 30" listen="%spop3" prefork=0 maxchild=%s' % (pre, maxchild)
			print '        pop3sproxy cmd="pop3proxyd -C /etc/imapd/frontend.conf -s -U 30" listen="%spop3s" prefork=0 maxchild=%s' % (pre, maxchild)

		# currently we leave it up to postfix to route mail to the backends
		# so we leave this commented out
		print ''
		print '        # proxy lmtp'
		print '        localLmtpproxy cmd="lmtpproxyd -C /etc/imapd/frontend.conf -a" listen="localhost:2003" prefork=0 maxchild=20'
		print '        lmtpproxy cmd="lmtpproxyd -C /etc/imapd/frontend.conf" listen="%s2003" prefork=0 maxchild=20' % pre
		print ''
		print '        # ----------------------------------------------'
@!@
