[buildout]

parts =
  boinc-server
  boinc-app
  certificate-authority
  ca-stunnel
  logrotate
  logrotate-entry-apache
  logrotate-entry-stunnel
  cron
  cron-entry-logrotate
  cron-entry-boinc
  promise
  frontend-promise
  content-promise
  publish-connection-informations

eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
#temporary solution
newest = false
offline = false


# Creation of all needed directories
[rootdirectory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc/
var = $${buildout:directory}/var/
srv = $${buildout:directory}/srv/
bin = $${buildout:directory}/bin/
tmp = $${buildout:directory}/tmp/
project = $${buildout:directory}/projects/

[basedirectory]
recipe = slapos.cookbook:mkdirectory
log = $${rootdirectory:var}/log/
services = $${rootdirectory:etc}/service/
scripts = $${rootdirectory:etc}/run/
run = $${rootdirectory:var}/run/
backup = $${rootdirectory:srv}/backup/
promises = $${rootdirectory:etc}/promise/
application = $${rootdirectory:tmp}/application
boinc = $${rootdirectory:tmp}/boinc

[directory]
recipe = slapos.cookbook:mkdirectory
ca-dir = $${rootdirectory:srv}/ssl/
httpd-log = $${basedirectory:log}/apache/
php-ini-dir = $${rootdirectory:etc}/php/
tmp-php = $${rootdirectory:tmp}/php/
logrotate-entries = $${rootdirectory:etc}/logrotate.d/
logrotate-backup = $${basedirectory:backup}/logrotate/
stunnel-conf = $${rootdirectory:etc}/stunnel/
cronstamps = $${rootdirectory:etc}/cronstamps/
cron-entries = $${rootdirectory:etc}/cron.d/
crontabs = $${rootdirectory:etc}/crontabs/

[cadirectory]
recipe = slapos.cookbook:mkdirectory
requests = $${directory:ca-dir}/requests/
private = $${directory:ca-dir}/private/
certs = $${directory:ca-dir}/certs/
newcerts = $${directory:ca-dir}/newcerts/
crl = $${directory:ca-dir}/crl/


# Deploy stunnel
[stunnel]
recipe = slapos.cookbook:stunnel
client = true
stunnel-binary = ${stunnel:location}/bin/stunnel
remote-host = $${mariadb-urlparse:host}
remote-port = $${mariadb-urlparse:port}
local-host = $${slap-network-information:local-ipv4}
local-port = 3306
log-file = $${basedirectory:log}/stunnel.log
config-file = $${directory:stunnel-conf}/stunnel.conf
key-file = $${directory:stunnel-conf}/stunnel.key
cert-file = $${directory:stunnel-conf}/stunnel.crt
pid-file = $${basedirectory:run}/stunnel.pid
wrapper = $${rootdirectory:bin}/raw_stunnel
post-rotate-script = $${rootdirectory:bin}/stunnel_post_rotate


# Certificate stuffs
[certificate-authority]
recipe = slapos.cookbook:certificate_authority
openssl-binary = ${openssl:location}/bin/openssl
ca-dir = $${directory:ca-dir}
requests-directory = $${cadirectory:requests}
wrapper = $${basedirectory:services}/ca
ca-private = $${cadirectory:private}
ca-certs = $${cadirectory:certs}
ca-newcerts = $${cadirectory:newcerts}
ca-crl = $${cadirectory:crl}

[ca-stunnel]
<= certificate-authority
recipe = slapos.cookbook:certificate_authority.request
executable = $${stunnel:wrapper}
wrapper = $${basedirectory:services}/stunnel
key-file = $${stunnel:key-file}
cert-file = $${stunnel:cert-file}


# Request MariaDB instance and parse its URL
[request-mariadb]
<= slap-connection
recipe = slapos.cookbook:request
name = MariaDB
software-url = $${slap-connection:software-release-url}
software-type = mariadb
return = url

[mariadb-urlparse]
recipe = slapos.cookbook:urlparse
url = $${request-mariadb:connection-url}

[httpd-conf]
recipe = slapos.recipe.template
url = ${template-httpd-conf:location}/${template-httpd-conf:filename}
output = $${rootdirectory:etc}/apache.conf

document_root = $${rootdirectory:srv}/www/
pid_file = $${basedirectory:run}/apache.pid
lock_file = $${basedirectory:run}/apache.lock
cgid_sock = $${basedirectory:run}/cgid.sock
ip = $${slap-network-information:global-ipv6}
port = 8080
error_log = $${directory:httpd-log}/error.log
access_log = $${directory:httpd-log}/access.log
php_ini_dir = $${directory:php-ini-dir}
niceprojectname = $${slap-parameter:project}@HOME
project = $${slap-parameter:project}
installroot = $${rootdirectory:project}/$${slap-parameter:project}
result_dir = $${rootdirectory:project}/$${slap-parameter:project}/sample_results/

[environment]
PATH = $${rootdirectory:bin}:${subversion:location}/bin:${perl:location}/bin:%(PATH)s

# Deploy Apache + PHP application
[apache-php]
recipe = slapos.cookbook:apachephp
source = $${basedirectory:application}

default-conf = false
httpd-conf = $${httpd-conf:output}
pid-file = $${basedirectory:run}/apache.pid
lock-file = $${basedirectory:run}/apache.lock
error-log = $${directory:httpd-log}/error.log
access-log = $${directory:httpd-log}/access.log
wrapper = $${basedirectory:services}/apache
ip = $${httpd-conf:ip}
port = $${httpd-conf:port}
url = http://[$${:ip}]:$${:port}/
httpd-binary = ${apache:location}/bin/httpd
htdocs = $${rootdirectory:srv}/www/
tmp-dir = $${directory:tmp-php}
php-ini-dir = $${directory:php-ini-dir}

mysql-username = $${mariadb-urlparse:username}
mysql-password = $${mariadb-urlparse:password}
mysql-database = $${mariadb-urlparse:path}
mysql-host = $${stunnel:local-host}
mysql-port = $${stunnel:local-port}
#send environment variable for apache process
environment-section =
  environment

template = 
configuration = 

[boinc-passwd]
recipe = slapos.cookbook:generate.password
storage-path = $${rootdirectory:etc}/.boincpasswd
bytes = 4

#deploy boinc server instance now
#Boinc server depend on apache-php instance
[boinc-server]
recipe = slapos.cookbook:boinc
home = $${buildout:directory}
project = $${slap-parameter:project}
#url-base = http://[$${apache-php:ip}]:$${apache-php:port}/
url-base = $${request-frontend:connection-site_url}
fullname = $${slap-parameter:full-name}
copyright = $${slap-parameter:copyright-holder}
boinc = ${boinc:location}
installroot = $${rootdirectory:project}/$${slap-parameter:project}
wrapper-dir = $${basedirectory:scripts}
source = ${boinc:source}
passwd = $${boinc-passwd:storage-path}
#Manualy add develop-egg and boinc-egg to pythonpath
develop-egg = ${buildout:develop-eggs-directory}

#Other binary path
svn-binary = ${subversion:location}/bin
perl-binary = ${perl:location}/bin
python-binary = ${buildout:executable}
dash = ${dash:location}/bin/dash

#Apache and php
htpasswd  = ${apache:location}/bin/htpasswd
apache-pid = $${httpd-conf:pid_file}
php-ini = $${apache-php:php-ini-dir}/php.ini
php-bin = ${apache-php:location}/bin/php
php-wrapper = $${rootdirectory:bin}php

#Mysql Informations
mysql-username = $${mariadb-urlparse:username}
mysql-password = $${mariadb-urlparse:password}
mysql-database = $${mariadb-urlparse:path}
mysql-host = $${stunnel:local-host}
mysql-port = $${stunnel:local-port}

#This allow to deploy or to update Boinc application using only slapparameters from
#vifib BOINC instance parameters
[boinc-app]
<= boinc-server
recipe = slapos.cookbook:boinc.app
#appname and version is require to update any existing application
#otherwise, the recipe would try to install a new one
boinc-app-list  = $${slap-parameter:boinc-app-list}
default-template-result = $${slap-parameter:default-template-result}
default-template-wu = $${slap-parameter:default-template-wu}
default-extension = $${slap-parameter:default-extension}
default-platform = $${slap-parameter:default-platform}

# Deploy logrotate, cron, configure it
[logrotate]
recipe = slapos.cookbook:logrotate
# Binaries
logrotate-binary = ${logrotate:location}/usr/sbin/logrotate
gzip-binary = ${gzip:location}/bin/gzip
gunzip-binary = ${gzip:location}/bin/gunzip
# Directories
wrapper = $${rootdirectory:bin}/logrotate
conf = $${rootdirectory:etc}/logrotate.conf
logrotate-entries = $${directory:logrotate-entries}
backup = $${directory:logrotate-backup}
state-file = $${rootdirectory:srv}/logrotate.status

[logrotate-entry-apache]
<= logrotate
recipe = slapos.cookbook:logrotate.d
name = apache
log = $${httpd-conf:error_log} $${httpd-conf:access_log}
frequency = daily
rotate-num = 30
sharedscripts = true
notifempty = true
create = true

[logrotate-entry-stunnel]
<= logrotate
recipe = slapos.cookbook:logrotate.d
name = stunnel
log = $${stunnel:log-file}
frequency = daily
rotate-num = 30
notifempty = true
create = true
post = $${stunnel:post-rotate-script}

[cron-simplelogger]
recipe = slapos.cookbook:simplelogger
wrapper = $${rootdirectory:bin}/cron_simplelogger
log = $${basedirectory:log}/crond.log

[cron]
recipe = slapos.cookbook:cron
dcrond-binary = ${dcron:location}/sbin/crond
cron-entries = $${directory:cron-entries}
crontabs = $${directory:crontabs}
cronstamps = $${directory:cronstamps}
catcher = $${cron-simplelogger:wrapper}
binary = $${basedirectory:services}/crond

[cron-entry-logrotate]
<= cron
recipe = slapos.cookbook:cron.d
name = logrotate
frequency = 0 0 * * *
command = $${logrotate:wrapper}

[cron-entry-boinc]
<= cron
recipe = slapos.cookbook:cron.d
name = cronjob
frequency = 0,5,10,15,20,25,30,35,40,45,50,55 * * * *
command = PATH=$${rootdirectory:bin}:$PATH $${boinc-server:installroot}/bin/start --cron


# Request frontend
[request-frontend]
<= slap-connection
recipe = slapos.cookbook:requestoptional
name = 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
slave = true
config-url = http://[$${apache-php:ip}]:$${apache-php:port}/
return = site_url
config-custom_domain = $${slap-parameter:domain}


# Publish all instance parameters (url of instance)
[publish-connection-informations]
recipe = slapos.cookbook:publish
boinc_admin_page = $${boinc-server:admin_page}
boinc_result_url = $${boinc-server:result_page}
boinc_home_page = $${boinc-server:home_page}
boinc_user = $${boinc-server:user}
boinc_passwd = $${boinc-passwd:passwd}


# Deploy promises scripts
[promise]
recipe = slapos.cookbook:check_port_listening
path = $${basedirectory:promises}/apache
hostname = $${apache-php:ip}
port = $${apache-php:port}

[frontend-promise]
recipe = slapos.cookbook:check_url_available
path = $${basedirectory:promises}/frontend
url = $${request-frontend:connection-site_url}/$${slap-parameter:project}
dash_path = ${dash:location}/bin/dash
curl_path = ${curl:location}/bin/curl

[content-promise]
recipe = slapos.cookbook:check_page_content
path = $${basedirectory:promises}/content
url = $${request-frontend:connection-site_url}/$${slap-parameter:project}
match = $${slap-parameter:full-name}
dash_path = ${dash:location}/bin/dash
curl_path = ${curl:location}/bin/curl

[slap-parameter]
#Default config value for boinc
project = boinc_test
full-name = Boinc Project SAMPLE
copyright-holder = REPLACE WITH COPYRIGHT HOLDER
#definition of BOINC parameter
#boinc-app-list is a Json data for all application to deploy
# boinc-app-list  = {"MY_APP1":{VERSION1:{
#                   use_default:true, "binary":"MY_BINARY",
#                   "platform":"", "extension":"", "template-result":"",
#                   "template-wu":"", "wu-number":1, "input-file":"INPUT"},
#                   "VERSION2":{use_default:false, ...}}}
# "app-name" parameter is now boinc-app-list[key]
boinc-app-list  = ${boinc-application:app-list}
default-template-result = ${boinc-default:template-result}
default-template-wu = ${boinc-default:template-wu}
default-extension = ${boinc-default:extension}
default-platform = ${boinc-default:platform}
# Default value if no domain is specified
domain = 
