###############################
# Instanciate nvu
###############################
[basedirectory]
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
# tomcat directories
catalina_base = $${:var}/vnu
catalina_logs = $${:catalina_base}/logs
catalina_temp = $${:catalina_base}/temp
catalina_webapps = $${:catalina_base}/webapps
catalina_work = $${:catalina_base}/work
catalina_conf = $${:catalina_base}/conf

#################################
# Tomcat service
#################################
[keystore]
recipe = plone.recipe.command
command =
  ${java-re-8-output:keytool} \
    -genkeypair \
    -alias "tomcat" \
    -keyalg RSA \
    -keypass "$${:pass}" \
    -dname "CN=Web Server,OU=Unit,O=Organization,L=City,S=State,C=Country" \
    -keystore "$${:file}" \
    -storepass "$${:pass}"
file = $${basedirectory:catalina_base}/.keystore
pass = insecure

[tomcat-service]
recipe = slapos.recipe.template
url = ${template-tomcat-service:output}
output = $${basedirectory:services}/tomcat
virtual-depends =
  $${tomcat-configuration:ip}

[tomcat-configuration]
recipe = slapos.recipe.template
url = ${template-tomcat-configuration:output}
output = $${basedirectory:catalina_conf}/server.xml
ip = {{ partition_ipv6 }}
port = 8899
scheme = https

[tomcat-listen-promise]
<= monitor-promise-base
promise = check_socket_listening
name = tomcat_listen.py
config-host = $${tomcat-configuration:ip}
config-port = $${tomcat-configuration:port}

#################################
# Slapos publish
#################################
[publish-url]
recipe = slapos.cookbook:publish
<= monitor-publish
vnu-url = $${tomcat-configuration:scheme}://[$${tomcat-configuration:ip}]:$${tomcat-configuration:port}/

[monitor-instance-parameter]
monitor-httpd-port = 8333

# Add parts generated by template
[buildout]
extends =
  ${monitor-template:output}
parts =
  publish-url
  tomcat-service
  tomcat-listen-promise
  monitor-base

eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true
