[directory]
recipe = slapos.cookbook:mkdirectory
etc = ${buildout:directory}/etc
bin = ${buildout:directory}/bin
srv = ${buildout:directory}/srv
var = ${buildout:directory}/var
run = ${:var}/run
log = ${:var}/log
scripts = ${:etc}/run
services = ${:etc}/service
plugins = ${:etc}/plugin
ssl = ${:etc}/ssl
www = ${:srv}/www
tmp = ${:srv}/tmp


#################################
# httpd service
#################################
[gen-certificate]
recipe = plone.recipe.command
command = "{{ parameter_dict['openssl'] }}" req -newkey rsa -batch -new -x509 -days 3650 -nodes -keyout "${:ssl_key}" -out "${:ssl_crt}"
stop-on-error = true
ssl_crt = ${directory:ssl}/httpd.crt
ssl_key = ${directory:ssl}/httpd.key

[httpd-wrapper]
recipe = slapos.cookbook:simplehttpserver
host = {{ (ipv6 | list)[0] }}
port = 9083
base-path = ${directory:www}
wrapper = ${directory:services}/http-server
log-file = ${directory:log}/httpd.log
use-hash-url = false
cert-file = ${gen-certificate:ssl_crt}
key-file = ${gen-certificate:ssl_key}

[request-jscrawler-frontend]
<= slap-connection
recipe = slapos.cookbook:requestoptional
name = jscawler Frontend
# XXX We have hardcoded SR URL here.
software-url = http://git.erp5.org/gitweb/slapos.git/blob_plain/HEAD:/software/apache-frontend/software.cfg
shared = true
config-url = https://[${httpd-wrapper:host}]:${httpd-wrapper:port}
return = secure_access domain

[jscrawler-frontend-promise]
<= monitor-promise-base
promise = check_url_available
name = jscrawler_frontend.py
config-url = ${request-jscrawler-frontend:connection-secure_access}

[logrotate-entry-httpd]
<= logrotate-entry-base
name = http-server
log = ${httpd-wrapper:log-file}


[httpd-listen-promise]
<= monitor-promise-base
promise = check_socket_listening
name = httpd-listen.py
config-host = ${httpd-wrapper:host}
config-port = ${httpd-wrapper:port}

[jscrawler-wrapper]
recipe = slapos.cookbook:wrapper
command-line =
  {{ parameter_dict['nodejs-location'] }} {{ parameter_dict['jscrawler-location'] }}
wrapper-path = ${directory:bin}/jscrawler

[jscrawler-build-wrapper]
recipe = slapos.recipe.template:jinja2
url = {{ parameter_dict['template-jscrawler'] }}
output = ${directory:bin}/jscrawler-build
extensions = jinja2.ext.do
list = {{ slapparameter_dict.get('urls', "").split("\n") | join('\n  ') }}
period = {{ slapparameter_dict.get('crawl-periodicity', 0) }}
context =
  key public_folder directory:www
  key tmp_folder directory:tmp
  key jscrawler_wrapper jscrawler-wrapper:wrapper-path
  key period :period
  key url_list :list
  raw shell_binary {{ bash_executable_location }}
  raw pid_file ${directory:run}/jscrawler.pid

[cron-entry-build-sitemap]
<= cron
recipe = slapos.cookbook:cron.d
name = jscrawler-build
frequency = * * * * *
command = ${jscrawler-build-wrapper:output}


[publish-connection-information]
<= monitor-publish
recipe = slapos.cookbook:publish
url = ${request-jscrawler-frontend:connection-secure_access}

[buildout]
extends = {{ template_monitor }}

parts =
  publish-connection-information
  logrotate-entry-httpd
# crawler cron
  cron-entry-build-sitemap
  httpd-wrapper
  httpd-listen-promise
  jscrawler-frontend-promise

eggs-directory = {{ eggs_directory }}
develop-eggs-directory = {{ develop_eggs_directory }}
offline = true
