instance-export.cfg.jinja.in 3.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
{%- set parameter_dict = dict(default_parameter_dict, **parameter_dict) -%}

[buildout]
extends = {{ theia_instance_cfg }}
          {{ pbsready_export_cfg }}

parts +=
  monitor-base
  $${:theia-parts}
  $${:theia-environment-parts}
  resilient-publish-connection-parameter


# The resilient stack makes the 'resilient' instance
# request the 'export' instance with a 'namebase' parameter.
# The export template then expects to receive it in
# slap-parameter:namebase
[slap-parameter]
namebase = {{ parameter_dict['namebase'] }}


# The resilient export stack periodically calls exporter:wrapper
# and then notifies the pull-backup instance that data is ready
# to be pulled from the export instance.
# All it expects is that a script be available in exporter:wrapper.
[exporter]
27 28 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
wrapper = $${theia-export-script:rendered}

[theia-export-script]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:bin}/theia-export-script
mode = 0700
exitcode-file = $${directory:srv}/export-exitcode-file
error-file = $${directory:srv}/export-errormessage-file
context =
  raw python ${software-info:python-with-eggs}
  raw theia_export ${software-info:theia-export}
  raw bash ${software-info:bash}
  raw rsync ${software-info:rsync}
  raw sqlite3 ${software-info:sqlite3}
  raw root_path $${buildout:directory}
  raw backup_path $${directory:backup}
  raw slapos_cfg $${directory:runner}/etc/slapos.cfg
  raw project_path $${directory:project}
  raw public_path $${directory:frontend-static-public}
  key exitfile :exitcode-file
  key errorfile :error-file
{%- raw %}
template =
  inline:#!{{ bash }}
  {{ python }} {{ theia_export }} \
  --rsync {{ rsync }} \
  --sqlite3 {{ sqlite3 }} \
  --root {{ root_path }} \
  --backup {{ backup_path }} \
  --cfg {{ slapos_cfg }} \
  --dirs {{ project_path }} \
  --dirs {{ public_path }} \
  --exitfile {{ exitfile }} \
  --errorfile {{ errorfile }}
{%- endraw %}

63

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
# Add a promise to check that the export script has run
# successfully and recently (at most 2 days ago).
[promises]
export-promises =
  $${export-promise:name}

[export-promise]
<= monitor-promise-base
module = check_command_execute
name = resiliency-export-promise.py
config-command = $${export-promise-script:rendered}

[initial-export-exitcode-file]
recipe = slapos.recipe.template:jinja2
rendered = $${theia-export-script:exitcode-file}
template = inline:0
once = $${:rendered}

[export-promise-script]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:bin}/export-promise-script
exitcode-file = $${initial-export-exitcode-file:rendered}
context =
  key exitcodefile :exitcode-file
  key errorfile theia-export-script:error-file
{%- raw %}
template =
  inline:#!/bin/sh
  if [ -z $(find {{ repr(exitcodefile) }} -mtime -2) ]
  then
    echo "ERROR export script last ran on " $(date -r {{ repr(exitcodefile) }})
    exit 1
  elif [ $( cat {{ repr(exitcodefile) }}) -ne 0 ]
  then
    echo "ERROR export script failed on " $(date -r {{ repr(exitcodefile) }})
    cat {{ repr(errorfile) }}
    exit 1
  else
    echo "OK export script last ran on " $(date -r {{ repr(exitcodefile) }})
    exit 0
  fi
{%- endraw %}


108 109 110
# Extend resilient parameters with normal theia connection parameters
[resilient-publish-connection-parameter]
<= publish-connection-parameter