instance-pullrdiffbackup.cfg.in 6.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
{% set part_list = [] -%}
{% set crontab_line_list = [] -%}
###############################
#
# Instanciate dcron
#
###############################

[directory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc
bin = $${buildout:directory}/bin
srv = $${buildout:directory}/srv
var = $${buildout:directory}/var
15
run = $${:var}/run
16 17 18 19 20 21 22 23
log = $${:var}/log
# scripts = $${:etc}/run
services = $${:etc}/service
cron-entries = $${:etc}/cron.d
cron-lines = $${:etc}/cron.lines
crontabs = $${:etc}/crontabs
cronstamps = $${:etc}/cronstamps
backup = $${:srv}/backup
24
status = $${:srv}/status
25
backupscript = $${:etc}/backup
26
www = $${:srv}/www
27
home = $${:etc}/home
28
ssl = $${:etc}/ssl
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
ssh = $${:home}/.ssh

#################################
# Cron service
#################################
[dcron-service]
recipe = slapos.recipe.template
url = ${template-dcron-service:output}
output = $${directory:services}/crond
mode = 0700
logfile = $${directory:log}/crond.log

#################################
# Slave backup scripts and crontab
#################################
# Go throught slave list to set their configuration
{% for slave_instance in slave_instance_list -%}
{%   set slave_reference = slave_instance.get('slave_reference') -%}
{%   set frequency = slave_instance.get('frequency', '') -%}
{%   set hostname = slave_instance.get('hostname', '') -%}
{%   set connection = slave_instance.get('connection', '') -%}
{%   set include = slave_instance.get('include', '') -%}
{%   set include_string = "' --include='".join(include.split(' ')) -%}
{%   set exclude = slave_instance.get('exclude', '') -%}
{%   set exclude_string = '' -%}
{%   set sudo = slave_instance.get('sudo', 'False') -%}
{%   set remote_schema = 'rdiff-backup --server --restrict-read-only / -- "$@"' -%}

{%   if (exclude != '') -%}
{%     set exclude_string = "' --exclude='".join(exclude.split(' ')) -%}
{%     set exclude_string = "--exclude='" + exclude_string + "'" -%}
{%   endif -%}

{%   if (sudo == 'True') -%}
{%     set remote_schema = 'sudo backupagent_rdiff-backup' -%}
{%   endif -%}

{%   if (frequency != '') and (hostname != '') and (connection != '') and (include != '') -%}

[{{ slave_reference }}-backup-directory]
recipe = slapos.cookbook:mkdirectory
directory = $${directory:backup}/$${:_buildout_section_name_}

[{{ slave_reference }}-backup-private_key]
recipe = plone.recipe.command
stop-on-error = true
command = ${dropbear-output:keygen} -t $${:type} -s 2048 -f $${:key} 
key = $${directory:ssh}/$${:_buildout_section_name_}
location = $${:key}
type = rsa

[{{ slave_reference }}-backup-public_key]
recipe = plone.recipe.command
stop-on-error = true
command = ${coreutils-output:rm} -f $${:key} && ${dropbear-output:keygen} -y -f {{ '$${' ~ slave_reference }}-backup-private_key:key} | ${grep-output:grep} {{ '$${' ~ slave_reference }}-backup-private_key:type} > $${:key}
key = {{ '$${' ~ slave_reference }}-backup-private_key:key}.pub
location = $${:key}
86 87
# Insert as a beginning part, to ensure that all public keys are generated before trying to publish. This will reduce the number of slapgrid-cp run.
{%   do part_list.insert(0, "%s-backup-public_key" % slave_reference) -%}
88 89

[{{ slave_reference }}-backup-read-public_key]
90
recipe = slapos.cookbook:readline
91 92 93 94 95 96
storage-path = {{ '$${' ~ slave_reference }}-backup-public_key:key}

# Publish slave {{ slave_reference }} information
[{{ slave_reference }}-backup-publish]
recipe = slapos.cookbook:publish
-slave-reference = {{ slave_reference }}
97
authorized_key = {{ '$${' ~ slave_reference }}-backup-read-public_key:readline}
98
rss = https://[$${nginx-configuration:ip}]:$${nginx-configuration:port}/{{ '$${' ~ slave_reference }}-backup-script:status_name}.rss
99 100 101 102 103 104 105 106 107 108 109 110 111 112
{%   do part_list.append("%s-backup-publish" % slave_reference) -%}

[{{ slave_reference }}-backup-script]
recipe = slapos.recipe.template
url = ${template-backup-script:output}
output = $${directory:backupscript}/$${:_buildout_section_name_}
mode = 0700
datadirectory = {{ '$${' ~ slave_reference }}-backup-directory:directory}
sshkey = {{ '$${' ~ slave_reference }}-backup-private_key:key}
connection = {{ connection }}
hostname = {{ hostname }}
include = {{ include_string }}
exclude_string = {{ exclude_string }}
remote_schema = {{ remote_schema }}
113 114
status_name = {{ slave_reference }}_status.txt
status_log = $${directory:status}/$${:status_name}
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

[{{ slave_reference }}-backup-crontab-line]
recipe = slapos.recipe.template
url = ${template-crontab-line:output}
output = $${directory:cron-lines}/$${:_buildout_section_name_}
mode = 0600
script = {{ '$${' ~ slave_reference }}-backup-script:output}
frequency = {{ frequency }}
{%   do crontab_line_list.append("$${%s-backup-crontab-line:output}" % slave_reference) -%}

{%   endif -%}
{% endfor -%}

#################################
# Generate crontab file
#################################
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
[update-rss-script]
recipe = slapos.recipe.template
url = ${template-update-rss-script:output}
output = $${directory:etc}/$${:_buildout_section_name_}
mode = 0700
global_rss = $${slap-connection:computer-id}-$${slap-connection:partition-id}.rss

[update-rss-crontab-line]
recipe = slapos.recipe.template
url = ${template-crontab-line:output}
output = $${directory:cron-lines}/$${:_buildout_section_name_}
mode = 0600
script = $${update-rss-script:output}
frequency = */5 * * * *
{% do crontab_line_list.append("$${update-rss-crontab-line:output}") -%}

[publish-global-rss]
recipe = slapos.cookbook:publish
rss = https://[$${nginx-configuration:ip}]:$${nginx-configuration:port}/$${update-rss-script:global_rss}
150 151 152 153 154 155 156 157

{% set crontab_line_list_string = " ".join(crontab_line_list) -%}
[activate-crontab-file]
# XXX File is never removed
recipe = plone.recipe.command
stop-on-error = true
command = ${coreutils-output:cat} ${template-crontab:output} {{ crontab_line_list_string }} | ${dcron-output:crontab} -c $${directory:crontabs} -

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
#################################
# Nginx service
#################################
[nginx-service]
recipe = slapos.recipe.template
url = ${template-nginx-service:output}
output = $${directory:services}/nginx
mode = 0700
virtual-depends = 
  $${nginx-configuration:ip}

[nginx-configuration]
recipe = slapos.recipe.template
url = ${template-nginx-configuration:output}
output = $${directory:etc}/nginx.cfg
mode = 0600
access_log = $${directory:log}/nginx-access.log
error_log = $${directory:log}/nginx-error.log
ip = $${slap-network-information:global-ipv6}
port = 9443
ssl_key = $${directory:ssl}/nginx.key
ssl_csr = $${directory:ssl}/nginx.csr
ssl_crt = $${directory:ssl}/nginx.crt
181 182 183 184 185

# Add parts generated by template
[buildout]
parts =
  dcron-service
186
  nginx-service
187
  activate-crontab-file
188
  publish-global-rss
189 190 191 192 193 194 195
{% for part in part_list -%}
{{ '    %s' % part }}
{% endfor -%}

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