instance-pullrdiffbackup.cfg.in 8.31 KB
Newer Older
1 2 3 4 5 6 7 8
{% set part_list = [] -%}
{% set crontab_line_list = [] -%}
###############################
#
# Instanciate dcron
#
###############################

9 10 11 12
[variables]
status_dirbasename = status
statistic_dirbasename = statistic

13 14 15 16 17 18
[directory]
recipe = slapos.cookbook:mkdirectory
etc = $${buildout:directory}/etc
bin = $${buildout:directory}/bin
srv = $${buildout:directory}/srv
var = $${buildout:directory}/var
19
run = $${:var}/run
20
log = $${:var}/log
21
varnginx = $${:var}/nginx
22 23 24 25 26 27 28
# 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
29 30
status = $${:srv}/$${variables:status_dirbasename}
statistic = $${:srv}/$${variables:statistic_dirbasename}
31
backupscript = $${:etc}/backup
32
www = $${:srv}/www
33
home = $${:etc}/home
34
ssl = $${:etc}/ssl
35
ssh = $${:home}/.ssh
36
plugin = $${:etc}/plugin
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

#################################
# 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 -%}
53 54
{%   set orig_slave_reference = slave_instance.get('slave_reference') -%}
{%   set slave_reference = orig_slave_reference.replace(' ', '_') -%}
55 56 57
{%   set frequency = slave_instance.get('frequency', '') -%}
{%   set hostname = slave_instance.get('hostname', '') -%}
{%   set connection = slave_instance.get('connection', '') -%}
58
{%   set connection_port = slave_instance.get('connection_port', '22') -%}
59 60 61 62 63
{%   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') -%}
64
{%   set remote_schema = slave_instance.get('remote_rdiff_path', 'rdiff-backup') + ' --server --restrict-read-only / -- "$@"' -%}
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

{%   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
83 84
stop-on-error = true
command = ${coreutils-output:rm} -f $${:key} $${:public_key} && ${openssh-output:keygen} -t $${:type} -b 2048 -f $${:key} -q -N ""
85
key = $${directory:ssh}/$${:_buildout_section_name_}
86 87
public_key = $${:key}.pub
location = $${:public_key}
88 89
type = rsa

90
# 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.
91
{%   do part_list.insert(0, "%s-backup-private_key" % slave_reference) -%}
92 93

[{{ slave_reference }}-backup-read-public_key]
94
recipe = slapos.cookbook:readline
95
storage-path = {{ '$${' ~ slave_reference }}-backup-private_key:public_key}
96 97 98 99

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

105 106 107 108 109
[{{ slave_reference }}-promise-check-backup]
recipe = slapos.cookbook:promise.plugin
eggs =
  slapos.toolbox
output = $${directory:plugin}/{{ slave_reference }}_check_backup.py
110
module = slapos.promise.plugin.backupserver_check_backup
111 112 113 114 115 116 117 118 119 120
config-status_dirbasename = $${variables:status_dirbasename}
config-status_name = {{ '$${' ~ slave_reference }}-backup-script:status_name}
config-status_fullpath = {{ '$${' ~ slave_reference }}-backup-script:status_log}
config-script_fullpath = {{ '$${' ~ slave_reference }}-backup-script:output}
config-cron_frequency = {{ frequency }}
config-monitor_url = $${monitor-publish:monitor-base-url}
config-statistic_dirbasename = $${variables:statistic_dirbasename}
config-statistic_name = {{ '$${' ~ slave_reference }}-backup-script:statistic_name}
{%   do part_list.append("%s-promise-check-backup" % slave_reference) -%}

121 122 123 124 125 126 127 128
[{{ 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 }}
129
connection_port = {{ connection_port }}
130 131 132 133
hostname = {{ hostname }}
include = {{ include_string }}
exclude_string = {{ exclude_string }}
remote_schema = {{ remote_schema }}
134
status_name = {{ slave_reference }}_status.txt
135
statistic_name = {{ slave_reference }}_statistic.txt
136
status_log = $${directory:status}/$${:status_name}
137
statistic_log = $${directory:statistic}/$${:statistic_name}
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

[{{ 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
#################################
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
[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
172
<= monitor-publish
173
rss = https://[$${nginx-configuration:ip}]:$${nginx-configuration:port}/$${update-rss-script:global_rss}
174 175 176 177 178 179 180 181

{% 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} -

182 183 184 185 186 187 188 189 190 191 192
#################################
# Nginx service
#################################
[nginx-service]
recipe = slapos.recipe.template
url = ${template-nginx-service:output}
output = $${directory:services}/nginx
mode = 0700
virtual-depends = 
  $${nginx-configuration:ip}

193
[nginx-listen-promise]
194
<= monitor-promise-base
195
promise = check_socket_listening
196
name = nginx_listen.py
197
config-host = $${nginx-configuration:ip}
198
config-port = $${nginx-configuration:port}
199

200 201 202 203 204 205 206
[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
207
ip = {{ partition_ipv6 }}
208 209 210 211
port = 9443
ssl_key = $${directory:ssl}/nginx.key
ssl_csr = $${directory:ssl}/nginx.csr
ssl_crt = $${directory:ssl}/nginx.crt
212

213 214 215 216 217 218 219 220 221 222 223
#################################
# Monitoring
#################################
[monitor-instance-parameter]
monitor-httpd-port = 9687

[monitor-conf-parameters]
private-path-list +=
  $${directory:statistic}
  $${directory:status}

224 225
# Add parts generated by template
[buildout]
226 227 228 229
extends =
  ${monitor-template:rendered}


230 231
parts =
  dcron-service
232
  nginx-service
233
  nginx-listen-promise
234
  activate-crontab-file
235
  publish-global-rss
236
  monitor-base
237 238 239 240 241 242 243
{% for part in part_list -%}
{{ '    %s' % part }}
{% endfor -%}

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