[buildout]

parts =
  urls
  apache-proxy
  logrotate
  logrotate-entry-apache
  cron
  cron-entry-logrotate
  sshkeys-authority
  sshkeys-dropbear
  dropbear-server
  dropbear-server-pbs-authorized-key
  request-pull-backup-server-apache-backup
  agent
  agent-wrapper
  watchdog
  logrotate-entry-equeue

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

[urls]
recipe = slapos.cookbook:publish
url = http://[$${apache-proxy:ip}]:$${apache-proxy:port}/
agent-url = $${agent-data:url}

[apache-proxy]
recipe = slapos.cookbook:apacheproxy
url = $${slap-parameter:proxy-url}
pid-file = $${basedirectory:run}/apache.pid
lock-file = $${basedirectory:run}/apache.lock
ip = $${slap-network-information:global-ipv6}
port = 8080
error-log = $${directory:httpd-log}/error.log
access-log = $${directory:httpd-log}/access.log
httpd-conf = $${rootdirectory:etc}/apache.conf
wrapper = $${basedirectory:services}/apache

promise = $${basedirectory:promises}/apache

httpd-binary = ${apache:location}/bin/httpd

[sshkeys-directory]
recipe = slapos.cookbook:mkdirectory
requests = $${directory:sshkeys}/requests/
keys = $${directory:sshkeys}/keys/

[sshkeys-authority]
recipe = slapos.cookbook:sshkeys_authority
request-directory = $${sshkeys-directory:requests}
keys-directory = $${sshkeys-directory:keys}
wrapper = $${basedirectory:services}/sshkeys_authority
keygen-binary = ${dropbear:location}/bin/dropbearkey

[sshkeys-dropbear]
<= sshkeys-authority
recipe = slapos.cookbook:sshkeys_authority.request
name = dropbear
type = rsa
executable = $${dropbear-server:wrapper}
public-key = $${dropbear-server:rsa-keyfile}.pub
private-key = $${dropbear-server:rsa-keyfile}
wrapper = $${basedirectory:services}/sshd

[dropbear-server]
recipe = slapos.cookbook:dropbear
host = $${slap-network-information:global-ipv6}
port = 2222
home = $${directory:ssh}
wrapper = $${rootdirectory:bin}/raw_sshd
shell = $${rdiff-backup-server:wrapper}
rsa-keyfile = $${directory:ssh}/server_key.rsa
dropbear-binary = ${dropbear:location}/sbin/dropbear

[dropbear-server-pbs-authorized-key]
<= dropbear-server
recipe = slapos.cookbook:dropbear.add_authorized_key
key = $${slap-parameter:authorized-key}

[rdiff-backup-server]
recipe = slapos.cookbook:pbs
client = false
path = $${directory:htdocs}
wrapper = $${rootdirectory:bin}/rdiffbackup-server
rdiffbackup-binary = ${buildout:bin-directory}/rdiff-backup

[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 = $${apache-proxy:error-log} $${apache-proxy:access-log}
frequency = daily
rotate-num = 30
sharedscripts = true
notifempty = true
create = true

[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-simplelogger]
recipe = slapos.cookbook:simplelogger
wrapper = $${rootdirectory:bin}/cron_simplelogger
log = $${basedirectory:log}/crond.log

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

[request-pull-backup-server-apache-backup]
<= slap-connection
recipe = slapos.cookbook:request
name = Pull Backup Server pushing to backup Apache
software-url = $${slap-connection:software-release-url}
software-type = pull-backup
slave = true
config = url id type request-agent-url authorized-key
config-url = ssh://nobody@[$${dropbear-server:host}]:$${dropbear-server:port}/$${rdiff-backup-server:path}
config-id = $${slap-parameter:pbs-id}
config-type = push
config-request-agent-url = http://[$${agent-data:host}]:$${agent-data:port}/
config-authorized-key = $${sshkeys-dropbear:public-key-value}
return = feed-url agent-url

[logrotate-entry-equeue]
<= logrotate
recipe = slapos.cookbook:logrotate.d
name = equeue
log = $${equeue:log}
frequency = daily
rotate-num = 30

[equeue]
recipe = slapos.cookbook:equeue
socket = $${basedirectory:run}/equeue.sock
log = $${basedirectory:log}/equeue.log
database = $${rootdirectory:srv}/equeue.db
wrapper = $${basedirectory:services}/equeue
equeue-binary = ${buildout:bin-directory}/equeue

[agent-data]
host = $${slap-network-information:global-ipv6}
port = 8081
url = http://[$${:host}]:$${:port}/

[agent]
<= agent-data
   slap-connection
recipe = slapos.cookbook:agent
database = $${rootdirectory:srv}/agent.db
equeue-socket = $${equeue:socket}
callbacks-directory = $${directory:agent-callbacks}
wrapper = $${rootdirectory:bin}/agent
gunicorn = ${buildout:bin-directory}/gunicorn
partition-id = $${slap-connection:partition-id}
computer-id = $${slap-connection:computer-id}
config-file = $${rootdirectory:etc}/agent.py
peers =
    $${slap-parameter:request-agent-url}
    $${request-pull-backup-server-apache-backup:connection-agent-url}

[agent-wrapper]
recipe = slapos.cookbook:submanager
subcommand = $${agent:wrapper}
wrapper = $${basedirectory:services}/agent
pid-file = $${basedirectory:run}/agent.pid
binary = ${buildout:bin-directory}/submanager
config-files =
    $${agent:config-file}

[watchdog]
recipe = slapos.cookbook:watchdog
agent-url = $${agent-data:url}
wrapper = $${basedirectory:services}/watchdog
binary = ${buildout:bin-directory}/wp-watchdog
partition-id = $${slap-connection:partition-id}
computer-id = $${slap-connection:computer-id}

[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/

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

[directory]
recipe = slapos.cookbook:mkdirectory
htdocs = $${rootdirectory:srv}/www/
logrotate-entries = $${rootdirectory:etc}/logrotate.d/
logrotate-backup = $${basedirectory:backup}/logrotate/
cronstamps = $${rootdirectory:etc}/cronstamps/
cron-entries = $${rootdirectory:etc}/cron.d/
crontabs = $${rootdirectory:etc}/crontabs/
ssh = $${rootdirectory:etc}/ssh/
sshkeys = $${rootdirectory:srv}/sshkeys/
httpd-log = $${basedirectory:log}/apache/
agent-callbacks = $${basedirectory:agent}/callbacks/