instance-apache-frontend.cfg.in 38.8 KB
Newer Older
1
{%- if slap_software_type == software_type -%}
2
{% import "caucase" as caucase with context %}
Łukasz Nowak's avatar
Łukasz Nowak committed
3
{%- set TRUE_VALUES = ['y', 'yes', '1', 'true'] -%}
4 5 6 7
[buildout]
extends =
  {{ parameter_dict['common_profile'] }}
  {{ parameter_dict['monitor_template'] }}
8
  {{ parameter_dict['logrotate_base_instance'] }}
9 10 11 12 13 14

parts =
  directory
  logrotate-entry-caddy
  caddy-frontend
  switch-caddy-softwaretype
15
  caucase-updater
16
  caucase-updater-promise
17 18
  backend-client-caucase-updater
  backend-client-caucase-updater-promise
19 20 21 22 23 24 25
  frontend-caddy-graceful
  port-redirection
  promise-frontend-caddy-configuration
  promise-caddy-frontend-v4-https
  promise-caddy-frontend-v4-http
  promise-caddy-frontend-v6-https
  promise-caddy-frontend-v6-http
26
  promise-logrotate-setup
27 28 29 30 31 32 33 34

  trafficserver-launcher
  trafficserver-reload
  trafficserver-configuration-directory
  trafficserver-records-config
  trafficserver-remap-config
  trafficserver-plugin-config
  trafficserver-storage-config
35
  trafficserver-ip-allow-config
36
  trafficserver-logging-yaml
37 38
  trafficserver-promise-listen-port
  trafficserver-promise-cache-availability
39
  cron-entry-logrotate-trafficserver
40 41 42 43 44 45 46
## Monitor for Caddy
  monitor-base
  monitor-ats-cache-stats-wrapper
  monitor-traffic-summary-last-stats-wrapper
  monitor-caddy-server-status-wrapper
  monitor-verify-re6st-connectivity

47 48 49
  backend-haproxy-rsyslogd-configuration
  backend-haproxy-rsyslogd
  logrotate-entry-backend-haproxy
50 51 52 53 54 55
  backend-haproxy
  backend-haproxy-graceful
  promise-backend-haproxy-http
  promise-backend-haproxy-https
  promise-backend-haproxy-configuration

56 57 58 59 60 61 62 63 64
  slave-introspection-frontend
  slave-introspection-graceful
  promise-slave-introspection-https
  promise-slave-introspection-configuration
  logrotate-entry-slave-introspection

[caddyprofiledeps]
recipe = caddyprofiledeps

65 66 67 68 69 70 71 72
# Create all needed directories
[directory]
recipe = slapos.cookbook:mkdirectory

bin = ${buildout:directory}/bin/
etc = ${buildout:directory}/etc/
srv = ${buildout:directory}/srv/
var = ${buildout:directory}/var/
73
tmp = ${:var}/tmp
74 75 76 77 78
template = ${buildout:directory}/template/

backup = ${:srv}/backup
log = ${:var}/log
run = ${:var}/run
79
backend-haproxy-rsyslogd-spool = ${:run}/backend-haproxy-rsyslogd-spool
80 81 82 83
service = ${:etc}/service
etc-run = ${:etc}/run

ca-dir = ${:srv}/ssl
84
backend-client-dir = ${:srv}/backend-client
85 86 87
# BBB: SlapOS Master non-zero knowledge BEGIN
bbb-ssl-dir = ${:srv}/bbb-ssl
# BBB: SlapOS Master non-zero knowledge END
88

89 90
frontend_cluster = ${:var}/frontend_cluster

91 92 93 94 95
# csr_id publication
csr_id = ${:srv}/csr_id
caddy-csr_id = ${:etc}/caddy-csr_id
caddy-csr_id-log = ${:log}/httpd-csr_id

96 97 98
# slave introspection
slave-introspection-var = ${:var}/slave-introspection

99 100 101 102 103 104 105 106
[switch-caddy-softwaretype]
recipe = slapos.cookbook:softwaretype
single-default = ${dynamic-custom-personal-template-slave-list:rendered}
single-custom-personal = ${dynamic-custom-personal-template-slave-list:rendered}

[frontend-configuration]
template-log-access = {{ parameter_dict['template_log_access'] }}
log-access-configuration = ${directory:etc}/log-access.conf
107
ip-access-certificate = ${self-signed-ip-access:certificate}
108 109 110
caddy-directory = {{ parameter_dict['caddy_location'] }}
caddy-ipv6 = {{ instance_parameter['ipv6-random'] }}
caddy-https-port = ${configuration:port}
111 112 113 114 115 116 117 118
nginx = {{ parameter_dict['nginx'] }}
nginx_mime = {{ parameter_dict['nginx_mime'] }}
htpasswd = {{ parameter_dict['htpasswd'] }}
slave-introspection-template = {{ parameter_dict['template_slave_introspection_httpd_nginx'] }}
slave-introspection-configuration = ${directory:etc}/slave-introspection-httpd-nginx.conf
slave-introspection-https-port = ${configuration:slave-introspection-https-port}
slave-introspection-secure_access = ${slave-introspection-frontend:connection-secure_access}
slave-introspection-domain = ${slave-introspection-frontend:connection-domain}
119

120 121 122 123 124 125
[self-signed-ip-access]
# Self Signed certificate for HTTPS IP accesses to the frontend
recipe = plone.recipe.command
update-command = ${:command}
ipv6 = ${slap-network-information:global-ipv6}
ipv4 = {{instance_parameter['ipv4-random']}}
126
certificate = ${caddy-directory:master-autocert-dir}/ip-access-${:ipv6}-${:ipv4}.crt
127 128
stop-on-error = True
command =
129 130
  [ -f ${:certificate} ] && exit 0
  rm -f ${:certificate}
131
  /bin/bash -c ' \
132
  {{ parameter_dict['openssl'] }} req \
133 134
     -new -newkey rsa:2048 -sha256 \
     -nodes -x509 -days 36500 \
135
     -keyout ${:certificate} \
136 137 138
     -subj "/CN=Self Signed IP Access" \
     -reqexts SAN \
     -extensions SAN \
139
     -config <(cat {{ parameter_dict['openssl_cnf'] }} \
140 141 142
         <(printf "\n[SAN]\nsubjectAltName=IP:${:ipv6},IP:${:ipv4}")) \
     -out ${:certificate}'

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
[self-signed-fallback-access]
# Self Signed certificate for HTTPS access to the frontend with fallback certificate
recipe = plone.recipe.command
update-command = ${:command}
ipv6 = ${slap-network-information:global-ipv6}
ipv4 = {{instance_parameter['ipv4-random']}}
certificate = ${caddy-directory:master-autocert-dir}/fallback-access.crt
stop-on-error = True
command =
  [ -f ${:certificate} ] && exit 0
  rm -f ${:certificate}
  /bin/bash -c ' \
  {{ parameter_dict['openssl'] }} req \
     -new -newkey rsa:2048 -sha256 \
     -nodes -x509 -days 36500 \
     -keyout ${:certificate} \
     -subj "/CN=Fallback certificate/OU={{ instance_parameter['configuration.frontend-name'] }}" \
     -out ${:certificate}'

162 163 164
[jinja2-template-base]
recipe = slapos.recipe.template:jinja2
rendered = ${buildout:directory}/${:filename}
165
extensions = jinja2.ext.do
166 167 168 169 170 171
extra-context =
slapparameter_dict = {{ dumps(instance_parameter['configuration']) }}
slap_software_type = {{ dumps(instance_parameter['slap-software-type']) }}
context =
    import json_module json
    raw common_profile {{ parameter_dict['common_profile'] }}
172
    raw logrotate_base_instance {{ parameter_dict['logrotate_base_instance'] }}
173
    raw monitor_template {{ parameter_dict['monitor_template'] }}
174 175 176 177 178 179 180 181
    key slap_software_type :slap_software_type
    key slapparameter_dict :slapparameter_dict
    section directory directory
    ${:extra-context}

[software-release-path]
template-empty = {{ parameter_dict['template_empty'] }}
template-default-slave-virtualhost = {{ parameter_dict['template_default_slave_virtualhost'] }}
182
template-backend-haproxy-configuration = {{ parameter_dict['template_backend_haproxy_configuration'] }}
183
template-backend-haproxy-rsyslogd-conf = {{ parameter_dict['template_backend_haproxy_rsyslogd_conf'] }}
184 185
caddy-location = {{ parameter_dict['caddy_location'] }}

186 187
[kedifa-login-config]
d = ${directory:ca-dir}
188
template-csr = ${:d}/kedifa-login-template-csr.pem
189 190 191 192 193 194 195 196 197 198 199 200
key = ${:d}/kedifa-login-certificate.pem
certificate = ${:key}
ca-certificate = ${:d}/kedifa-caucase-ca.pem
cas-ca-certificate = ${:d}/kedifa-cas-caucase-ca.pem
crl = ${:d}/kedifa-login-crl.pem

[kedifa-login-csr]
recipe = plone.recipe.command
organization = {{ slapparameter_dict['cluster-identification'] }}
organizational_unit = {{ instance_parameter['configuration.frontend-name'] }}
command =
{% if slapparameter_dict['kedifa-caucase-url'] %}
201
  if [ ! -f ${:template-csr} ] && [ ! -f ${:key} ]  ; then
202 203 204
    {{ parameter_dict['openssl'] }} req -new -sha256 \
      -newkey rsa:2048 -nodes -keyout ${:key} \
      -subj "/O=${:organization}/OU=${:organizational_unit}" \
205
      -out ${:template-csr}
206 207
  fi
{% endif %}
208
  test -f ${:key} && test -f ${:template-csr}
209
update-command = ${:command}
210
template-csr = ${kedifa-login-config:template-csr}
211 212 213 214 215 216 217 218 219 220 221 222 223
key = ${kedifa-login-config:key}
stop-on-error = True

{{ caucase.updater(
     prefix='caucase-updater',
     buildout_bin_directory=parameter_dict['bin_directory'],
     updater_path='${directory:service}/kedifa-login-certificate-caucase-updater',
     url=slapparameter_dict['kedifa-caucase-url'],
     data_dir='${directory:srv}/caucase-updater',
     crt_path='${kedifa-login-config:certificate}',
     ca_path='${kedifa-login-config:ca-certificate}',
     crl_path='${kedifa-login-config:crl}',
     key_path='${kedifa-login-csr:key}',
224
     template_csr='${kedifa-login-csr:template-csr}'
225 226
)}}

227 228 229 230 231 232 233 234 235 236 237 238
[kedifa-configuration]
caucase-url = {{ slapparameter_dict['kedifa-caucase-url'] }}
ca-certificate = ${kedifa-login-config:ca-certificate}
certificate = ${kedifa-login-config:certificate}
cas-ca-certificate = ${kedifa-login-config:cas-ca-certificate}
csr = ${caucase-updater-csr:csr}
crl = ${kedifa-login-config:crl}
kedifa-updater = {{ parameter_dict['kedifa-updater'] }}
kedifa-updater-mapping-file = ${directory:etc}/kedifa_updater_mapping.txt
kedifa-updater-state-file = ${directory:srv}/kedifa_updater_state.json
slave_kedifa_information = {{ dumps(slapparameter_dict['slave-kedifa-information']) }}

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
[backend-client-login-config]
d = ${directory:backend-client-dir}
template-csr = ${:d}/csr.pem
key = ${:d}/certificate.pem
certificate = ${:key}
ca-certificate = ${:d}/ca.pem
cas-ca-certificate = ${:d}/cas-ca.pem
crl = ${:d}/crl.pem

[backend-client-login-csr]
recipe = plone.recipe.command
organization = {{ slapparameter_dict['cluster-identification'] }}
organizational_unit = {{ instance_parameter['configuration.frontend-name'] }}
command =
{% if slapparameter_dict['backend-client-caucase-url'] %}
  if [ ! -f ${:template-csr} ] && [ ! -f ${:key} ]  ; then
    {{ parameter_dict['openssl'] }} req -new -sha256 \
      -newkey rsa:2048 -nodes -keyout ${:key} \
      -subj "/O=${:organization}/OU=${:organizational_unit}" \
      -out ${:template-csr}
  fi
{% endif %}
  test -f ${:key} && test -f ${:template-csr}
update-command = ${:command}
template-csr = ${backend-client-login-config:template-csr}
key = ${backend-client-login-config:key}
stop-on-error = True

{{ caucase.updater(
     prefix='backend-client-caucase-updater',
     buildout_bin_directory=parameter_dict['bin_directory'],
     updater_path='${directory:service}/backend-client-login-certificate-caucase-updater',
     url=slapparameter_dict['backend-client-caucase-url'],
     data_dir='${directory:srv}/backend-client-caucase-updater',
     crt_path='${backend-client-login-config:certificate}',
     ca_path='${backend-client-login-config:ca-certificate}',
     crl_path='${backend-client-login-config:crl}',
     key_path='${backend-client-login-csr:key}',
     template_csr='${backend-client-login-csr:template-csr}'
)}}

280 281
[dynamic-custom-personal-template-slave-list]
< = jinja2-template-base
282
depends = ${caddyprofiledeps:recipe}
283 284 285
template = {{ parameter_dict['template_slave_list'] }}
filename = custom-personal-instance-slave-list.cfg
slave_instance_list = {{ dumps(instance_parameter['slave-instance-list']) }}
286
extra_slave_instance_list = {{ dumps(instance_parameter.get('configuration.extra_slave_instance_list')) }}
287
master_key_download_url = {{ dumps(slapparameter_dict['master-key-download-url']) }}
288 289
local_ipv4 = {{ dumps(instance_parameter['ipv4-random']) }}
local_ipv6 = {{ dumps(instance_parameter['ipv6-random']) }}
290 291
software_type = single-custom-personal
bin_directory = {{ parameter_dict['bin_directory'] }}
292
caddy_executable = {{ parameter_dict['caddy'] }}
293
sixtunnel_executable = {{ parameter_dict['sixtunnel'] }}/bin/6tunnel
294 295
organization = {{ slapparameter_dict['cluster-identification'] }}
organizational-unit = {{ instance_parameter['configuration.frontend-name'] }}
296
backend-client-caucase-url = {{ slapparameter_dict['backend-client-caucase-url'] }}
297 298
extra-context =
    key caddy_configuration_directory caddy-directory:slave-configuration
299
    key backend_client_caucase_url :backend-client-caucase-url
300
    import urlparse_module urlparse
301
    import furl_module furl
302
    key caddy_executable :caddy_executable
303 304 305 306 307
    key http_port configuration:plain_http_port
    key https_port configuration:port
    key public_ipv4 configuration:public-ipv4
    key slave_instance_list :slave_instance_list
    key extra_slave_instance_list :extra_slave_instance_list
308 309 310
    key master_key_download_url :master_key_download_url
    key autocert caddy-directory:autocert
    key master_certificate caddy-configuration:master-certificate
311
    key caddy_log_directory caddy-directory:slave-log
312 313
    key expose_csr_id_organization :organization
    key expose_csr_id_organizational_unit :organizational-unit
314 315 316 317 318
    key local_ipv4 :local_ipv4
    key local_ipv6 :local_ipv6
    key global_ipv6 slap-network-information:global-ipv6
    key empty_template software-release-path:template-empty
    key template_default_slave_configuration software-release-path:template-default-slave-virtualhost
319
    key software_type :software_type
320
    key frontend_lazy_graceful_reload frontend-caddy-lazy-graceful:rendered
321
    key frontend_graceful_reload caddy-configuration:frontend-graceful-command
322 323 324
    section frontend_configuration frontend-configuration
    section caddy_configuration caddy-configuration
    key monitor_base_url monitor-instance-parameter:monitor-base-url 
325
    key bin_directory :bin_directory
326
    key enable_http2_by_default configuration:enable-http2-by-default
327
    key global_disable_http2 configuration:global-disable-http2
328
    key ciphers configuration:ciphers
329 330
    key access_log caddy-configuration:access-log
    key error_log caddy-configuration:error-log
331
    key sixtunnel_executable :sixtunnel_executable
332
    key not_found_file caddy-configuration:not-found-file
333
    key custom_ssl_directory caddy-directory:custom-ssl-directory
334
    section kedifa_configuration kedifa-configuration
335
# BBB: SlapOS Master non-zero knowledge BEGIN
336 337
    key apache_certificate apache-certificate:rendered
# BBB: SlapOS Master non-zero knowledge END
338 339 340 341 342
## backend haproxy
    key template_backend_haproxy_configuration software-release-path:template-backend-haproxy-configuration
    section backend_haproxy_configuration backend-haproxy-configuration
## full configuration
    section configuration configuration
343 344 345 346 347 348 349 350 351 352 353

# Deploy Caddy Frontend with Jinja power
[dynamic-caddy-frontend-template]
< = jinja2-template-base
template = {{ parameter_dict['template_caddy_frontend_configuration'] }}
rendered = ${caddy-configuration:frontend-configuration}
local_ipv4 =  {{ dumps(instance_parameter['ipv4-random']) }}
extra-context =
    key httpd_home software-release-path:caddy-location
    key httpd_mod_ssl_cache_directory caddy-directory:mod-ssl
    key instance_home buildout:directory
354
    key master_certificate caddy-configuration:master-certificate
355 356 357 358 359 360 361 362 363 364 365
    key access_log caddy-configuration:access-log
    key slave_configuration_directory caddy-directory:slave-configuration
    section frontend_configuration frontend-configuration
    key http_port configuration:plain_http_port
    key https_port configuration:port
    key local_ipv4 :local_ipv4
    key global_ipv6 slap-network-information:global-ipv6
    key error_log caddy-configuration:error-log
    key not_found_file caddy-configuration:not-found-file
    key username monitor-instance-parameter:username
    key password monitor-htpasswd:passwd
366 367 368
# BBB: SlapOS Master non-zero knowledge BEGIN
    key apache_certificate apache-certificate:rendered
# BBB: SlapOS Master non-zero knowledge END
369 370

[caddy-wrapper]
371 372 373 374 375 376 377 378 379
recipe = slapos.recipe.template:jinja2
template = inline:
  #!/bin/sh
  export CADDYPATH=${directory:frontend_cluster}
  ulimit -n $(ulimit -Hn)
  exec {{ parameter_dict['caddy'] }} \
  -conf ${dynamic-caddy-frontend-template:rendered} \
  -log ${caddy-configuration:error-log} \
  -log-roll-mb 0 \
380
{% if instance_parameter['configuration.global-disable-http2'].lower() in TRUE_VALUES %}
381
  -http2=false \
382
{% else %}
383
  -http2=true \
Łukasz Nowak's avatar
Łukasz Nowak committed
384
{% endif %}
385 386 387 388 389 390
  -grace {{ instance_parameter['configuration.mpm-graceful-shutdown-timeout'] }}s \
  -disable-http-challenge \
  -disable-tls-alpn-challenge \
   "$@"
rendered = ${directory:bin}/caddy-wrapper
mode = 0755
391 392 393

[caddy-frontend]
recipe = slapos.cookbook:wrapper
394
command-line = ${caddy-wrapper:rendered} -pidfile ${caddy-configuration:pid-file}
395
wrapper-path = ${directory:service}/frontend_caddy
396
hash-existing-files = ${buildout:directory}/software_release/buildout.cfg
397
hash-files = ${caddy-wrapper:rendered}
398 399

[not-found-html]
400 401 402 403
recipe = plone.recipe.command
update-command = ${:command}
filename = notfound.html
command = ln -sf  {{ parameter_dict['template_not_found_html'] }} ${caddy-directory:document-root}/${:filename}
404 405 406 407 408 409 410 411

[caddy-directory]
recipe = slapos.cookbook:mkdirectory
document-root = ${directory:srv}/htdocs
slave-configuration = ${directory:etc}/caddy-slave-conf.d/
cache = ${directory:var}/cache
mod-ssl = ${:cache}/httpd_mod_ssl
slave-log = ${directory:log}/httpd
412 413
autocert = ${directory:srv}/autocert
master-autocert-dir = ${:autocert}/master-autocert
414
custom-ssl-directory = ${:slave-configuration}/ssl
415 416 417 418 419 420

[caddy-configuration]
frontend-configuration = ${directory:etc}/Caddyfile
access-log = ${directory:log}/frontend-access.log
error-log = ${directory:log}/frontend-error.log
pid-file = ${directory:run}/httpd.pid
421
frontend-graceful-command = ${frontend-caddy-validate:rendered} && kill -USR1 $(cat ${:pid-file})
422
not-found-file = ${caddy-directory:document-root}/${not-found-html:filename}
423
master-certificate = ${caddy-directory:master-autocert-dir}/master.pem
424 425
# Communication with ATS
cache-port = ${trafficserver-variable:input-port}
426 427 428 429 430
# slave instrspection
slave-introspection-access-log = ${directory:log}/slave-introspection-access.log
slave-introspection-error-log = ${directory:log}/slave-introspection-error.log
slave-introspection-pid-file = ${directory:run}/slave-introspection.pid
slave-introspection-graceful-command = ${slave-introspection-validate:rendered} && kill -HUP $(cat ${:slave-introspection-pid-file})
431

432
# BBB: SlapOS Master non-zero knowledge BEGIN
433 434 435 436 437
[get-self-signed-fallback-access]
recipe = collective.recipe.shelloutput
commands =
  certificate = cat ${self-signed-fallback-access:certificate}

438
[apache-certificate]
439 440 441
recipe = slapos.recipe.template:jinja2
template = inline:
{% raw %}
442 443
  {{ certificate or fallback_certificate }}
  {{ key or '' }}
444 445 446 447
{% endraw %}
context =
  key certificate configuration:apache-certificate
  key key configuration:apache-key
448
  key fallback_certificate get-self-signed-fallback-access:certificate
449 450 451
rendered = ${directory:bbb-ssl-dir}/frontend.crt
# BBB: SlapOS Master non-zero knowledge END

452
[logrotate-entry-caddy]
453
<= logrotate-entry-base
454 455
name = caddy
log = ${caddy-configuration:error-log} ${caddy-configuration:access-log}
456
rotate-num = ${configuration:rotate-num}
457 458 459 460 461
# Note: Slaves do not define their own reload, as this would be repeated,
#       because sharedscripts work per entry, and each slave needs its own
#       olddir
#       Here we trust that there will be something to be rotated with error
#       or access log, and that this will trigger postrotate script.
462
post = ${frontend-caddy-lazy-graceful:rendered} &
463
delaycompress =
464 465 466 467 468 469 470 471 472 473 474

#################
# Trafficserver
#################
[trafficserver-directory]
recipe = slapos.cookbook:mkdirectory
configuration = ${directory:etc}/trafficserver
local-state = ${directory:var}/trafficserver
bin_path = {{ parameter_dict['trafficserver'] }}/bin
log = ${directory:log}/trafficserver
cache-path = ${directory:srv}/ats_cache
475
logrotate-backup = ${logrotate-directory:logrotate-backup}/trafficserver
476 477 478 479 480 481 482

[trafficserver-variable]
wrapper-path = ${directory:service}/trafficserver
reload-path = ${directory:etc-run}/trafficserver-reload
local-ip = {{ instance_parameter['ipv4-random'] }}
input-port = 23432
hostname = ${configuration:frontend-name}
483 484
plugin-config =
ip-allow-config = src_ip=0.0.0.0-255.255.255.255 action=ip_allow
485 486 487
cache-path = ${trafficserver-directory:cache-path}
disk-cache-size = ${configuration:disk-cache-size}
ram-cache-size = ${configuration:ram-cache-size}
488
templates-dir = {{ parameter_dict['trafficserver'] }}/etc/trafficserver/body_factory
489
request-timeout = ${configuration:request-timeout}
490 491 492 493 494 495 496 497

[trafficserver-configuration-directory]
recipe = plone.recipe.command
command = cp -rn {{ parameter_dict['trafficserver'] }}/etc/trafficserver/* ${:target}
target = ${trafficserver-directory:configuration}

[trafficserver-launcher]
recipe = slapos.cookbook:wrapper
498
command-line = {{ parameter_dict['trafficserver'] }}/bin/traffic_manager
499 500
wrapper-path = ${trafficserver-variable:wrapper-path}
environment = TS_ROOT=${buildout:directory}
501
hash-existing-files = ${buildout:directory}/software_release/buildout.cfg
502 503 504

[trafficserver-reload]
recipe = slapos.cookbook:wrapper
505
command-line = {{ parameter_dict['trafficserver'] }}/bin/traffic_ctl config reload
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
wrapper-path = ${trafficserver-variable:reload-path}
environment = TS_ROOT=${buildout:directory}

# XXX Dedicated Jinja Section without slapparameter
[trafficserver-jinja2-template-base]
recipe = slapos.recipe.template:jinja2
rendered = ${trafficserver-directory:configuration}/${:filename}
extra-context =
mode = 600
context =
    section ats_directory trafficserver-directory
    section ats_configuration trafficserver-variable
    ${:extra-context}

[trafficserver-records-config]
< = trafficserver-jinja2-template-base
522
template = {{ parameter_dict['template_trafficserver_records_config'] }}
523 524 525 526 527 528
filename = records.config
extra-context =
    import os_module os

[trafficserver-storage-config]
< = trafficserver-jinja2-template-base
529
template = {{ parameter_dict['template_trafficserver_storage_config'] }}
530 531
filename = storage.config

532
[trafficserver-logging-yaml]
533
< = trafficserver-jinja2-template-base
534 535
template = {{ parameter_dict['template_trafficserver_logging_yaml'] }}
filename = logging.yaml
536

537
[trafficserver-remap-config]
538 539 540 541 542 543 544 545 546 547 548
<= trafficserver-jinja2-template-base
{%- raw %}
template = inline:
  map /HTTPS/ http://{{ ipv4 }}:{{ https_port }}
  map / http://{{ ipv4 }}:{{ http_port }}
{%- endraw %}
extra-context =
  raw ipv4 {{ instance_parameter['ipv4-random'] }}
  key https_port backend-haproxy-configuration:https-port
  key http_port backend-haproxy-configuration:http-port

549 550 551 552 553 554 555 556 557
filename = remap.config

[trafficserver-plugin-config]
< = trafficserver-jinja2-template-base
template = {{ parameter_dict['template_empty'] }}
filename = plugin.config
context =
    key content trafficserver-variable:plugin-config

558 559 560 561 562 563 564
[trafficserver-ip-allow-config]
< = trafficserver-jinja2-template-base
template = {{ parameter_dict['template_empty'] }}
filename = ip_allow.config
context =
    key content trafficserver-variable:ip-allow-config

565
[trafficserver-promise-listen-port]
566
<= monitor-promise-base
567 568 569 570
module = check_port_listening
name = trafficserver-port-listening.py
config-hostname = ${trafficserver-variable:local-ip}
config-port = ${trafficserver-variable:input-port}
571

572
[trafficserver-ctl]
573
recipe = slapos.cookbook:wrapper
574 575
command-line = {{ parameter_dict['trafficserver'] }}/bin/traffic_ctl
wrapper-path = ${directory:bin}/traffic_ctl
576 577 578
environment = TS_ROOT=${buildout:directory}

[trafficserver-promise-cache-availability]
579
<= monitor-promise-base
580 581
module = trafficserver_cache_availability
name = trafficserver-cache-availability.py
582
config-wrapper-path = ${trafficserver-ctl:wrapper-path}
583

584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
[trafficserver-rotate-script]
< = jinja2-template-base
template = {{ parameter_dict['template_rotate_script'] }}
rendered = ${directory:bin}/trafficserver-rotate
mode = 0700
xz_binary = {{ parameter_dict['xz_location'] ~ '/bin/xz' }}
pattern = *.old
# days to keep log files
keep_days = 365

extra-context =
  key log_dir trafficserver-directory:log
  key rotate_dir trafficserver-directory:logrotate-backup
  key xz_binary :xz_binary
  key keep_days :keep_days
  key pattern :pattern

[cron-entry-logrotate-trafficserver]
recipe = slapos.cookbook:cron.d
cron-entries = ${directory:etc}/cron.d
name = trafficserver-logrotate
frequency = 0 0 * * *
command = ${trafficserver-rotate-script:rendered}

608 609 610
### End of ATS sections

### Caddy Graceful and promises
611
[frontend-caddy-configuration-state]
612
< = jinja2-template-base
613 614
template = {{ parameter_dict['template_configuration_state_script'] }}
rendered = ${directory:bin}/${:_buildout_section_name_}
615
mode = 0700
616

617
path_list = ${caddy-configuration:frontend-configuration} ${frontend-configuration:log-access-configuration} ${caddy-directory:slave-configuration}/*.conf ${caddy-directory:master-autocert-dir}/*.key ${caddy-directory:master-autocert-dir}/*.crt ${caddy-directory:master-autocert-dir}/*.pem ${caddy-directory:autocert}/*.pem ${caddy-directory:custom-ssl-directory}/*.proxy_ca_crt ${directory:bbb-ssl-dir}/*.crt
618
sha256sum = {{ parameter_dict['sha256sum'] }}
619

620
extra-context =
621 622 623
    key path_list :path_list
    key sha256sum :sha256sum
    key signature_file :signature_file
624

625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
[frontend-caddy-configuration-state-graceful]
< = frontend-caddy-configuration-state
signature_file = ${directory:run}/graceful_configuration_state_signature

[frontend-caddy-configuration-state-validate]
< = frontend-caddy-configuration-state
signature_file = ${directory:run}/validate_configuration_state_signature

[frontend-caddy-graceful]
< = jinja2-template-base
template = {{ parameter_dict['template_graceful_script'] }}
rendered = ${directory:etc-run}/frontend-caddy-safe-graceful
mode = 0700

extra-context =
    key graceful_reload_command caddy-configuration:frontend-graceful-command
    key caddy_configuration_state frontend-caddy-configuration-state-graceful:rendered

643 644 645 646 647
[frontend-caddy-validate]
< = jinja2-template-base
template = {{ parameter_dict['template_validate_script'] }}
rendered = ${directory:bin}/frontend-caddy-validate
mode = 0700
648
last_state_file = ${directory:run}/caddy_configuration_last_state
649
validate_command = ${caddy-wrapper:rendered} -validate
650
extra-context =
651 652
    key validate_command :validate_command
    key configuration_state_command frontend-caddy-configuration-state-validate:rendered
653
    key last_state_file :last_state_file
654

655 656 657 658 659 660
[frontend-caddy-lazy-graceful]
< = jinja2-template-base
template = {{ parameter_dict['template_caddy_lazy_script_call'] }}
rendered = ${directory:bin}/frontend-caddy-lazy-graceful
mode = 0700
pid-file = ${directory:run}/lazy-graceful.pid
661
wait_time = 60
662 663
extra-context =
    key pid_file :pid-file
664
    key wait_time :wait_time
665 666 667
    key lazy_command caddy-configuration:frontend-graceful-command

# Promises checking configuration:
668 669 670 671 672 673 674 675 676 677 678
[promise-helper-last-configuration-state]
< = jinja2-template-base
template = {{ parameter_dict['template_empty'] }}
rendered = ${directory:bin}/frontend-read-last-configuration-state
mode = 0700
content =
  #!/bin/sh
  exit `cat ${frontend-caddy-validate:last_state_file}`
context =
    key content :content

679
[promise-frontend-caddy-configuration]
680
<= monitor-promise-base
681 682
module = validate_frontend_configuration
name = frontend-caddy-configuration-promise.py
683
config-verification-script = ${promise-helper-last-configuration-state:rendered}
684 685

[promise-caddy-frontend-v4-https]
686
<= monitor-promise-base
687 688 689 690
module = check_port_listening
name = caddy_frontend_ipv4_https.py
config-hostname = {{ instance_parameter['ipv4-random'] }}
config-port = ${configuration:port}
691 692

[promise-caddy-frontend-v4-http]
693
<= monitor-promise-base
694 695 696 697
module = check_port_listening
name = caddy_frontend_ipv4_http.py
config-hostname = {{ instance_parameter['ipv4-random'] }}
config-port = ${configuration:plain_http_port}
698 699

[promise-caddy-frontend-v6-https]
700
<= monitor-promise-base
701 702 703 704
module = check_port_listening
name = caddy_frontend_ipv6_https.py
config-hostname = {{ instance_parameter['ipv6-random'] }}
config-port = ${configuration:port}
705 706

[promise-caddy-frontend-v6-http]
707
<= monitor-promise-base
708 709 710 711
module = check_port_listening
name = caddy_frontend_ipv6_http.py
config-hostname = {{ instance_parameter['ipv6-random'] }}
config-port = ${configuration:plain_http_port}
712

713
[promise-backend-haproxy-http]
714
<= monitor-promise-base
715
module = check_port_listening
716
name = backend_haproxy_http.py
717
config-hostname = {{ instance_parameter['ipv4-random'] }}
718
config-port = ${backend-haproxy-configuration:http-port}
719

720
[promise-backend-haproxy-https]
721
<= monitor-promise-base
722
module = check_port_listening
723
name = backend_haproxy_https.py
724
config-hostname = {{ instance_parameter['ipv4-random'] }}
725 726 727 728 729
config-port = ${backend-haproxy-configuration:https-port}

[backend-haproxy-configuration]
file = ${directory:etc}/backend-haproxy.cfg
pid-file = ${directory:run}/backend-haproxy.pid
730
log-socket = ${backend-haproxy-rsyslogd-config:log-socket}
731 732 733
graceful-command = ${backend-haproxy-validate:rendered} && kill -USR2 $(cat ${:pid-file})
http-port = ${configuration:backend-haproxy-http-port}
https-port = ${configuration:backend-haproxy-https-port}
734 735 736 737 738 739 740
# Caucase related configuration
caucase-url = {{ slapparameter_dict['backend-client-caucase-url'] }}
ca-certificate = ${backend-client-login-config:ca-certificate}
certificate = ${backend-client-login-config:certificate}
cas-ca-certificate = ${backend-client-login-config:cas-ca-certificate}
csr = ${backend-client-caucase-updater-csr:csr}
crl = ${backend-client-login-config:crl}
741 742 743 744 745 746 747

[backend-haproxy]
recipe = slapos.cookbook:wrapper
command-line = {{ parameter_dict['haproxy_executable'] }} -f ${backend-haproxy-configuration:file}
wrapper-path = ${directory:service}/backend-haproxy
hash-existing-files = ${buildout:directory}/software_release/buildout.cfg

748 749 750 751 752 753 754 755 756 757 758 759
[backend-haproxy-rsyslogd-lazy-graceful]
< = jinja2-template-base
template = {{ parameter_dict['template_caddy_lazy_script_call'] }}
rendered = ${directory:bin}/backend-haproxy-rsyslogd-lazy-graceful
mode = 0700
pid-file = ${directory:run}/backend-haproxy-rsyslogd-lazy-graceful.pid
wait_time = 60
extra-context =
    key pid_file :pid-file
    key wait_time :wait_time
    key lazy_command backend-haproxy-rsyslogd-config:graceful-command

760 761 762
[logrotate-entry-backend-haproxy]
<= logrotate-entry-base
name = backend-haproxy
763
log = ${backend-haproxy-rsyslogd-config:log-file}
764
rotate-num = ${configuration:rotate-num}
765 766 767 768 769 770
# Note: Slaves do not define their own reload, as this would be repeated,
#       because sharedscripts work per entry, and each slave needs its own
#       olddir
#       Here we trust that there will be something to be rotated with error
#       or access log, and that this will trigger postrotate script.
post = ${backend-haproxy-rsyslogd-lazy-graceful:rendered} &
771
delaycompress =
772

773 774 775 776 777 778
[backend-haproxy-configuration-state]
<= jinja2-template-base
template = {{ parameter_dict['template_configuration_state_script'] }}
rendered = ${directory:bin}/${:_buildout_section_name_}
mode = 0700

779
path_list = ${backend-haproxy-configuration:file} ${backend-client-login-config:certificate}
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
sha256sum = {{ parameter_dict['sha256sum'] }}

extra-context =
    key path_list :path_list
    key sha256sum :sha256sum
    key signature_file :signature_file

[backend-haproxy-configuration-state-graceful]
<= backend-haproxy-configuration-state
signature_file = ${directory:run}/backend_haproxy_graceful_configuration_state_signature

[backend-haproxy-configuration-state-validate]
<= backend-haproxy-configuration-state
signature_file = ${directory:run}/backend_haproxy_validate_configuration_state_signature

[backend-haproxy-graceful]
< = jinja2-template-base
template = {{ parameter_dict['template_graceful_script'] }}
rendered = ${directory:etc-run}/backend-haproxy-safe-graceful
mode = 0700

extra-context =
    key graceful_reload_command backend-haproxy-configuration:graceful-command
    key caddy_configuration_state backend-haproxy-configuration-state-graceful:rendered

[backend-haproxy-validate]
<= jinja2-template-base
template = {{ parameter_dict['template_validate_script'] }}
rendered = ${directory:bin}/backend-haproxy-validate
mode = 0700
last_state_file = ${directory:run}/backend_haproxy_configuration_last_state
validate_command = {{ parameter_dict['haproxy_executable'] }} -f ${backend-haproxy-configuration:file} -c
extra-context =
    key validate_command :validate_command
    key configuration_state_command backend-haproxy-configuration-state-validate:rendered
    key last_state_file :last_state_file

[promise-backend-haproxy-configuration]
<= monitor-promise-base
module = validate_frontend_configuration
name = backend-haproxy-configuration.py
config-verification-script = ${promise-backend-haproxy-configuration-helper:rendered}

[promise-backend-haproxy-configuration-helper]
< = jinja2-template-base
template = {{ parameter_dict['template_empty'] }}
rendered = ${directory:bin}/backend-haproxy-read-last-configuration-state
mode = 0700
content =
  #!/bin/sh
  exit `cat ${backend-haproxy-validate:last_state_file}`
context =
    key content :content
833

834
[backend-haproxy-rsyslogd-config]
835 836 837
log-socket = ${directory:run}/bhlog.sck
log-file = ${directory:log}/backend-haproxy.log
pid-file = ${directory:run}/backend-haproxy-rsyslogd.pid
838 839 840 841 842 843 844 845
spool-directory = ${directory:backend-haproxy-rsyslogd-spool}
graceful-command = kill -HUP $(cat ${:pid-file})
caddy-log-directory = ${caddy-directory:slave-log}

[backend-haproxy-rsyslogd-configuration]
<= jinja2-template-base
template = ${software-release-path:template-backend-haproxy-rsyslogd-conf}
rendered = ${directory:etc}/backend-haproxy-rsyslogd.conf
846
extra-context =
847
  section configuration backend-haproxy-rsyslogd-config
848 849 850

[backend-haproxy-rsyslogd]
recipe = slapos.cookbook:wrapper
851
command-line = {{ parameter_dict['rsyslogd_executable'] }} -i ${backend-haproxy-rsyslogd-config:pid-file} -n -f ${backend-haproxy-rsyslogd-configuration:rendered}
852 853 854
wrapper-path = ${directory:service}/backend-haproxy-rsyslogd
hash-existing-files = ${buildout:directory}/software_release/buildout.cfg

855 856 857 858 859
#######
# Monitoring sections
#

[monitor-instance-parameter]
860 861 862
# Note: Workaround for monitor stack, which uses monitor-httpd-port parameter
#       directly, and in our case it can come from the network, thus resulting
#       with need to strip !py!'u'
863
monitor-httpd-port = {{ instance_parameter['configuration.monitor-httpd-port'] | int }}
864
password = {{ instance_parameter['configuration.monitor-password'] | string }}
865 866 867

[monitor-conf-parameters]
private-path-list += 
868
  ${logrotate-directory:logrotate-backup}
869 870 871 872 873


[monitor-traffic-summary-last-stats-wrapper]
< = jinja2-template-base
template = {{ parameter_dict['template_wrapper'] }}
874
rendered = ${directory:bin}/traffic-summary-last-stats_every_1_hour
875 876 877 878 879 880 881 882 883
mode = 0700
command = export TS_ROOT=${buildout:directory} && echo "<pre>$({{ parameter_dict['trafficserver'] }}/bin/traffic_logstats -f ${trafficserver-directory:log}/squid.blog)</pre>"
extra-context =
  key content monitor-traffic-summary-last-stats-wrapper:command

# Produce ATS Cache stats
[monitor-ats-cache-stats-wrapper]
< = jinja2-template-base
template = {{ parameter_dict['template_wrapper'] }}
884
rendered = ${directory:bin}/ats-cache-stats_every_1_hour
885 886 887 888 889 890 891 892
mode = 0700
command = export TS_ROOT=${buildout:directory} && echo "<pre>$({{ parameter_dict['trafficserver'] }}/bin/traffic_shell ${monitor-ats-cache-stats-config:rendered})</pre>"
extra-context =
  key content monitor-ats-cache-stats-wrapper:command

[monitor-caddy-server-status-wrapper]
< = jinja2-template-base
template = {{ parameter_dict['template_wrapper'] }}
893
rendered = ${directory:bin}/monitor-caddy-server-status-wrapper
894 895 896 897 898 899 900 901 902 903 904 905 906 907
mode = 0700
command = {{ parameter_dict['curl'] }}/bin/curl -s http://{{ instance_parameter['ipv4-random'] }}:${configuration:plain_http_port}/server-status -u ${monitor-instance-parameter:username}:${monitor-htpasswd:passwd} 2>&1
extra-context =
  key content monitor-caddy-server-status-wrapper:command

[monitor-ats-cache-stats-config]
< = jinja2-template-base
template = {{ parameter_dict['template_empty'] }}
rendered = ${trafficserver-configuration-directory:target}/cache-config.stats
mode = 644
context =
    raw content show:cache-stats

[monitor-verify-re6st-connectivity]
908
<= monitor-promise-base
909 910 911
module = check_url_available
name = re6st-connectivity.py
config-url = ${configuration:re6st-verification-url}
912 913 914 915 916 917 918 919 920 921 922

[port-redirection]
<= jinja2-template-base
template = inline:
  [{"srcPort": 80, "destPort": {{ '{{' }} http_port {{ '}}' }}}, {"srcPort": 443, "destPort": {{ '{{' }} https_port {{ '}}' }}}]
rendered = ${buildout:directory}/.slapos-port-redirect
mode = 0644
extra-context =
    key http_port configuration:plain_http_port
    key https_port configuration:port

923 924 925 926 927 928 929 930 931 932
[slave-introspection-frontend]
<= slap-connection
recipe = slapos.cookbook:requestoptional
name = Slave Introspection Frontend {{ instance_parameter['configuration.frontend-name'] }}
software-url = http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
slave = true
config-url = https://[${slap-network-information:global-ipv6}]:{{ instance_parameter['configuration.slave-introspection-https-port'] }}/
config-https-only = true
return = domain secure_access

933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
[slave-introspection-configuration-state]
<= jinja2-template-base
template = {{ parameter_dict['template_configuration_state_script'] }}
rendered = ${directory:bin}/${:_buildout_section_name_}
mode = 0700

path_list = ${frontend-configuration:slave-introspection-configuration} ${frontend-configuration:ip-access-certificate}
sha256sum = {{ parameter_dict['sha256sum'] }}

extra-context =
    key path_list :path_list
    key sha256sum :sha256sum
    key signature_file :signature_file

[slave-introspection-configuration-state-graceful]
<= slave-introspection-configuration-state
signature_file = ${directory:run}/slave_introspection_graceful_configuration_state_signature

[slave-introspection-configuration-state-validate]
<= slave-introspection-configuration-state
signature_file = ${directory:run}/slave_introspection_validate_configuration_state_signature

[slave-introspection-graceful]
< = jinja2-template-base
template = {{ parameter_dict['template_graceful_script'] }}
rendered = ${directory:etc-run}/slave-introspection-safe-graceful
mode = 0700

extra-context =
    key graceful_reload_command caddy-configuration:slave-introspection-graceful-command
    key caddy_configuration_state slave-introspection-configuration-state-graceful:rendered

[slave-introspection-validate]
<= jinja2-template-base
template = {{ parameter_dict['template_validate_script'] }}
rendered = ${directory:bin}/slave-introspection-validate
mode = 0700
last_state_file = ${directory:run}/slave_introspection_configuration_last_state
validate_command = {{ parameter_dict['nginx'] }} -c ${frontend-configuration:slave-introspection-configuration} -t
extra-context =
    key validate_command :validate_command
    key configuration_state_command slave-introspection-configuration-state-validate:rendered
    key last_state_file :last_state_file

[promise-slave-introspection-configuration]
<= monitor-promise-base
module = validate_frontend_configuration
name = slave-introspection-configuration.py
config-verification-script = ${promise-slave-introspection-configuration-helper:rendered}

[promise-slave-introspection-configuration-helper]
< = jinja2-template-base
template = {{ parameter_dict['template_empty'] }}
rendered = ${directory:bin}/slave-introspection-read-last-configuration-state
mode = 0700
content =
  #!/bin/sh
  exit `cat ${slave-introspection-validate:last_state_file}`
context =
    key content :content

[promise-slave-introspection-https]
<= monitor-promise-base
module = check_port_listening
name = slave_introspection_https.py
config-hostname = {{ instance_parameter['ipv6-random'] }}
config-port = ${frontend-configuration:slave-introspection-https-port}

[logrotate-entry-slave-introspection]
<= logrotate-entry-base
name = slave-introspection
1004
log = ${caddy-configuration:slave-introspection-access-log} ${caddy-configuration:slave-introspection-error-log}
1005 1006
rotate-num = ${configuration:rotate-num}
post = kill -USR1 $(cat ${caddy-configuration:slave-introspection-pid-file})
1007
delaycompress =
1008

1009 1010 1011 1012 1013 1014 1015
[promise-logrotate-setup]
<= monitor-promise-base
module = check_command_execute
name = ${:_buildout_section_name_}.py
config-command =
  ${logrotate:wrapper-path} -d

1016 1017 1018 1019 1020 1021
[configuration]
{%- for key, value in instance_parameter.iteritems() -%}
{%-   if key.startswith('configuration.') %}
{{ key.replace('configuration.', '') }} = {{ dumps(value) }}
{%-   endif -%}
{%- endfor -%}
1022
{%- endif -%} {# if slap_software_type == software_type #}