instance-postfix.cfg.in 8.34 KB
Newer Older
1 2
{% set part_list = [] -%}
{% macro section(name) %}{% do part_list.append(name) %}{{ name }}{% endmacro -%}
3 4 5 6 7
{% if slapparameter_dict['use-ipv6'] -%}
{%   set ip = '[' ~ (ipv6_set | list)[0] ~ ']' -%}
{% else -%}
{%   set ip = (ipv4_set | list)[0] -%}
{% endif -%}
8
{% set tcpv4_port = slapparameter_dict['tcpv4-port'] -%}
9 10 11 12 13 14
{% set relay = slapparameter_dict.get('relay', {}) -%}
{% set divert = slapparameter_dict.get('divert', []) -%}
{% set alias_dict = slapparameter_dict.get('alias-dict', {}) -%}
{% do alias_dict.setdefault('postmaster', [slapparameter_dict['postmaster']]) -%}
{% set smtpd_sasl_user = slapparameter_dict['smtpd-sasl-user'] -%}
{% set smtpd_sasl_password = slapparameter_dict['smtpd-sasl-password'] -%}
15
{% set milter_list = [] %}
16

17 18 19 20
[jinja2-template-base]
recipe = slapos.recipe.template:jinja2
mode = 644

21 22 23 24 25
[smtpd-password]
recipe = slapos.cookbook:generate.password
storage-path =

[{{ section('publish') }}]
26
recipe = slapos.cookbook:publish.serialised
27
url = {{ dumps('smtp://' ~ urllib.quote_plus(smtpd_sasl_user) ~ ':' ~ urllib.quote_plus(smtpd_sasl_password) ~ '@' ~ ip ~ ':' ~ tcpv4_port) }}
28 29 30 31 32

[directory]
recipe = slapos.cookbook:mkdirectory
etc = ${buildout:directory}/etc
promise = ${:etc}/promise
33 34 35 36
etc-postfix = ${:etc}/postfix
etc-cyrus = ${:etc}/cyrus
run = ${:etc}/run
bin = ${buildout:directory}/bin
37 38
usr = ${buildout:directory}/usr
var = ${buildout:directory}/var
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
var-lib = ${:var}/lib
var-lib-postfix = ${:var-lib}/postfix
var-spool = ${:var}/spool
var-spool-postfix = ${:var-spool}/postfix
# Not used at buildout level, presence needed by postfix.
var-spool-postfix-active = ${:var-spool-postfix}/active
var-spool-postfix-bounce = ${:var-spool-postfix}/bounce
var-spool-postfix-corrupt = ${:var-spool-postfix}/corrupt
var-spool-postfix-defer = ${:var-spool-postfix}/defer
var-spool-postfix-deferred = ${:var-spool-postfix}/deferred
var-spool-postfix-flush = ${:var-spool-postfix}/flush
var-spool-postfix-hold = ${:var-spool-postfix}/hold
var-spool-postfix-incoming = ${:var-spool-postfix}/incoming
var-spool-postfix-maildrop = ${:var-spool-postfix}/maildrop
var-spool-postfix-pid = ${:var-spool-postfix}/pid
var-spool-postfix-private = ${:var-spool-postfix}/private
var-spool-postfix-public = ${:var-spool-postfix}/public
var-spool-postfix-saved = ${:var-spool-postfix}/saved
var-spool-postfix-trace = ${:var-spool-postfix}/trace

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
{% if divert -%}
{%   set milter_port = tcpv4_port + 1 -%}
{%   set socket = 'inet:' ~ ip ~ ':' ~ milter_port -%}
[{{ section('divert-milter') }}]
recipe = slapos.cookbook:wrapper
command-line =
  '{{ parameter_dict['buildout-bin-directory'] }}/munnel'
  --listen '{{ socket }}'
  -- {{ ' '.join(divert) }}
wrapper-path = ${directory:run}/munnel
{%   do milter_list.append(socket) -%}

[{{ section('munnel-promise') }}]
recipe = slapos.cookbook:check_port_listening
path = ${directory:promise}/munnel
hostname = {{ ip }}
port = {{ milter_port }}
{% endif -%}

78 79 80 81 82 83 84
[configuration]
smtp = {{ dumps(tcpv4_port) }}
inet-interfaces = {{ dumps(ip) }}
alias-dict = {{ dumps(alias_dict) }}
relayhost = {{ dumps(relay.get('host')) }}
relay-sasl-credential = {{ dumps(relay.get('sasl-credential')) }}
cyrus-sasldb = ${directory:etc-cyrus}/postfix.gdbm
85
milter-list = {{ dumps(milter_list) }}
86 87 88 89

[userinfo]
recipe = slapos.cookbook:userinfo

90
[smtp-sasl-passwd]
91
< = jinja2-template-base
92 93 94 95 96 97 98 99 100 101
rendered = ${directory:etc-postfix}/sasl_passwd
{% if relay -%}
template = inline:{{ "{{ host }} {{ sasl_credential }}" }}
{%- else -%}
template = inline:
{%- endif %}
context =
    key host configuration:relayhost
    key sasl_credential configuration:relay-sasl-credential
mode = 600
102

103
[{{ section('cyrus-smtpd-conf') }}]
104
< = jinja2-template-base
105 106 107 108 109
rendered = ${directory:etc-cyrus}/smtpd.conf
template = inline:
    pwcheck_method: auxprop
    mech_list: PLAIN LOGIN
    sasldb_path: {{ '{{ sasldb }}' }}
110
context =
111
    key sasldb configuration:cyrus-sasldb
112

113 114 115 116 117 118 119
[{{ section('cyrus-smtpd-password') }}]
recipe = plone.recipe.command
stop-on-error = true
command =
  rm -f '${configuration:cyrus-sasldb}' &&
  echo '{{ smtpd_sasl_password }}' | '${wrapper-postfix-saslpasswd2:wrapper-path}' -pc '{{ smtpd_sasl_user }}'
update-command = ${:command}
120

121 122 123 124 125 126 127 128 129 130 131 132 133 134
[smtpd-ssl]
recipe = plone.recipe.command
stop-on-error = true
openssl = '{{ parameter_dict['openssl'] }}/bin/openssl'
cert = ${directory:etc-postfix}/smtpd.crt
key = ${directory:etc-postfix}/smtpd.pem
dh-512 = ${directory:etc-postfix}/dh512.pem
dh-2048 = ${directory:etc-postfix}/dh2048.pem
command =
  ${:openssl} dhparam -out '${:dh-512}' 512 &&
  ${:openssl} dhparam -out '${:dh-2048}' 2048 &&
  ${:update}
update =
  ${:openssl} req -newkey rsa -batch -new -x509 -days 3650 -nodes -keyout '${:key}' -out '${:cert}'
135

136
[{{ section('postfix-main-cf') }}]
137
< = jinja2-template-base
138 139 140 141 142 143 144 145 146 147 148 149 150 151
rendered = ${directory:etc-postfix}/main.cf
template = {{ parameter_dict['template-postfix-main-cf'] }}
context =
    key bin_directory directory:bin
    key usr_directory directory:usr
    key queue_directory directory:var-spool-postfix
    key data_directory directory:var-lib-postfix
    key spool_directory directory:var-spool
    key mail_owner userinfo:pw-name
    key setgid_group userinfo:gr-name
    key inet_interfaces configuration:inet-interfaces
    key relayhost configuration:relayhost
    key sasl_passwd typed-paths:smtp-sasl-passwd
    key aliases typed-paths:aliases
152
    key milter_list configuration:milter-list
153 154 155 156 157 158 159
    key cyrus_directory directory:etc-cyrus
    key cert smtpd-ssl:cert
    key key smtpd-ssl:key
    key dh_512 smtpd-ssl:dh-512
    key dh_2048 smtpd-ssl:dh-2048

[{{ section('postfix-master-cf') }}]
160
< = jinja2-template-base
161
rendered = ${directory:etc-postfix}/master.cf
162
template = {{ parameter_dict['template-postfix-master-cf'] }}
163
context = key smtp configuration:smtp
164 165

[aliases]
166
< = jinja2-template-base
167 168 169 170
template = {{ parameter_dict['template-postfix-aliases'] }}
rendered = ${directory:etc-postfix}/aliases
context =
    key alias_dict configuration:alias-dict
171

172 173 174 175
[typed-paths]
# Postfix-friendly rendering of file paths, prefixed with database type.
aliases = hash:${aliases:rendered}
smtp-sasl-passwd = hash:${smtp-sasl-passwd:rendered}
176

177
[{{ section('postalias-db') }}]
178 179
recipe = plone.recipe.command
stop-on-error = true
180
command = '${wrapper-postalias:wrapper-path}' '${typed-paths:aliases}' '${typed-paths:smtp-sasl-passwd}'
181 182
update-command = ${:command}

183 184 185 186
[wrapper-postfix-saslpasswd2]
recipe = slapos.cookbook:wrapper
command-line = '{{ parameter_dict['cyrus-sasl-location'] }}/sbin/saslpasswd2' -f '${configuration:cyrus-sasldb}'
wrapper-path = ${directory:bin}/saslpasswd2
187

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
[base-wrapper]
recipe = slapos.cookbook:wrapper
environment =
  MAIL_CONFIG=${directory:etc-postfix}
  SASL_CONF_PATH=${directory:etc-cyrus}

[base-bin-wrapper]
< = base-wrapper
command-line = ${:path}/${:basename}
wrapper-path = ${directory:bin}/${:basename}

[base-bin-bin-wrapper]
< = base-bin-wrapper
path = {{ parameter_dict['postfix-location'] }}/usr/bin

[base-sbin-bin-wrapper]
< = base-bin-wrapper
path = {{ parameter_dict['postfix-location'] }}/usr/sbin

{% for extend, basename_list in (
  (
    'base-bin-bin-wrapper',
    (
      'mailq',
      'newaliases',
    ),
  ),
  (
    'base-sbin-bin-wrapper',
    (
      'postalias',
      'postcat',
      'postconf',
      'postdrop',
      'postfix',
      'postkick',
      'postlock',
      'postlog',
      'postmap',
      'postmulti',
      'postqueue',
      'postsuper',
      'sendmail',
    ),
  ),
) %}
{%   for basename in basename_list -%}
[{{ section('wrapper-' ~ basename) }}]
< = {{ extend }}
basename = {{ basename }}
{%   endfor %}
{% endfor %}

[{{ section('postfix-symlinks-libexec') }}]
242 243 244 245 246
recipe = slapos.cookbook:symbolic.link
target-directory = ${directory:usr}
link-binary =
    {{ parameter_dict['postfix-location'] }}/usr/libexec

247 248 249 250
[{{ section('service-postfix-master') }}]
< = base-wrapper
command-line = ${directory:usr}/libexec/postfix/master
wrapper-path = ${directory:run}/postfix-master
251

252 253 254 255 256
[{{ section('postfix-promise') }}]
recipe = slapos.cookbook:check_port_listening
path = ${directory:promise}/postfix
hostname = {{ ip }}
port = {{ tcpv4_port }}
257

258 259 260 261 262
[{{ section('promise-check-computer-memory') }}]
recipe = slapos.cookbook:wrapper
wrapper-path = ${directory:promise}/check-computer-memory
command-line = "{{ parameter_dict["check-computer-memory-binary"] }}" -db ${monitor-instance-parameter:collector-db} --threshold "{{ slapparameter_dict["computer-memory-percent-threshold"] }}" --unit percent

263 264 265 266
[buildout]
extends = {{ logrotate_cfg }}
parts =
    {{ part_list | join('\n  ') }}