[buildout]
extends = {{ template_runner_path }}
          {{ pbsready_export_template_path }}

parts +=
  nginx_conf
  nginx-launcher
  certificate-authority
  ca-nginx
  logrotate-entry-nginx
  gunicorn-launcher
  gunicorn-graceful
  publish-connection-information
  slaprunner-promise
  apache-httpd-promise
  logrotate-entry-apache-httpd
  slaprunner-supervisord-wrapper
  runner-sshd-add-authorized-key
  runner-sshd-graceful
  runner-sshd-promise
  runner-sshkeys-authority
  runner-sshkeys-sshd
  runtestsuite
  symlinks
  shellinabox
  slapos-cfg
  cron-entry-prepare-software
  deploy-instance-parameters
  instance-software
  instance-software-type
  minishell-cwd
  bash-profile
  supervisord-wrapper
  supervisord-promise
  logrotate-entry-supervisord
  logrotate-entry-slapgrid
  httpd-graceful-wrapper
## Monitoring part
## Monitor for runner
  monitor-base
  monitor-check-resilient-feed-file
  monitor-check-webrunner-internal-instance

[proxy-free-port]
recipe = slapos.cookbook:free_port
minimum = 49980
maximum = 49989
ip = ${slap-network-information:local-ipv4}

[runner-free-port]
recipe = slapos.cookbook:free_port
minimum = 50005
maximum = 50014
ip = ${slap-network-information:global-ipv6}

[slaprunner]
proxy_port = ${proxy-free-port:port}
runner_port = ${runner-free-port:port}

[supervisord-free-port]
recipe = slapos.cookbook:free_port
minimum = 39986
maximum = 39995
ip = ${slaprunner:ipv4}

[supervisord]
port = ${supervisord-free-port:port}

[exporter]
recipe = slapos.recipe.template:jinja2
template = {{ exporter_script_path }}
rendered = ${directory:bin}/${slap-parameter:namebase}-exporter
# backward compatibility for resilient stack
wrapper = ${:rendered}
mode = 700
context =
  import sys sys
  import easy_install zc.buildout.easy_install
  section directory directory
  raw  backup_wait_time {{ backup_wait_time }}
  raw  output_log_file ${directory:log}/resilient.log
  raw  shell_binary {{ bash_executable_location }}
  raw  rsync_binary {{ rsync_executable_location }}

[monitor-httpd-free-port]
recipe = slapos.cookbook:free_port
minimum = 8437
maximum = 8446
ip = ${slap-network-information:global-ipv6}

# XXX Redefine Monitor parameters for runner-export
[monitor-instance-parameter]
monitor-httpd-port = ${monitor-httpd-free-port:port}
{% if slapparameter_dict.get('name', '') -%}
monitor-title = {{ slapparameter_dict['name'] }}
{% endif -%}
cors-domains = {{ slapparameter_dict.get('monitor-cors-domains', 'monitor.app.officejs.com') }}
{% if slapparameter_dict.get('monitor-username', '') -%}
username = {{ slapparameter_dict['monitor-username'] }}
{% endif -%}
{% if slapparameter_dict.get('monitor-password', '') -%}
password = {{ slapparameter_dict['monitor-password'] }}
{% endif -%}
{% if slapparameter_dict.get('monitor-url-list', '') -%}
monitor-url-list = {{ slapparameter_dict['monitor-url-list'] }}
{% endif -%}
instance-configuration =
  httpdcors cors-domain ${slaprunner-httpd-cors:location} ${httpd-graceful-wrapper:output}
configuration-file-path = ${buildout:directory}/knowledge0.cfg

# Extends publish section with resilient parameters
[publish-connection-information]
<= resilient-publish-connection-parameter

[monitor-check-resilient-feed-file]
recipe = slapos.recipe.template:jinja2
template = {{ monitor_check_resilient_feed_template_path }}
rendered = ${monitor-directory:reports}/check-create-resilient-feed-files
mode = 700
context =
  key input_feed_directory directory:notifier-feeds
  key monitor_feed_directory monitor-directory:public
  raw base_url http://[${notifier:host}]:${notifier:port}/get/
  raw python_executable ${buildout:executable}