Commit e6f228a3 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Improve slaprunner resilient recipe

parent d519b13e
############################################################################## ##############################################################################
# #
# Copyright (c) 2013 Vifib SARL and Contributors. All Rights Reserved. # Copyright (c) 2013 Vifib SARL and Contributors. All Rights Reserved.
...@@ -57,8 +58,24 @@ class ExportRecipe(GenericBaseRecipe): ...@@ -57,8 +58,24 @@ class ExportRecipe(GenericBaseRecipe):
content = textwrap.dedent("""\ content = textwrap.dedent("""\
#!%(shell-binary)s #!%(shell-binary)s
umask 077 umask 077
cd ~/%(srv-directory)s/ ; \\ sync_element () {
tar --exclude=runner/software/* -czf %(backup-directory)s/runner.tgz runner/ path=$1
backup_path=$2
shift 2
element_list=$*
for element in $element_list
do
cd $path;
if [ -f $element ] || [ -d $element ]; then
%(rsync-binary)s -avz --safe-links $element $backup_path;
fi
done
}
sync_element %(srv-directory)s/runner %(backup-directory)s/runner/ instance project proxy.db softwareLink
sync_element %(etc-directory)s %(backup-directory)s/etc/ .rcode .project .users
if [ -d %(backup-directory)s/runner/software ]; then
rm %(backup-directory)s/runner/software/*
fi
""" % self.options) """ % self.options)
self.createExecutable(wrapper, content=content) self.createExecutable(wrapper, content=content)
...@@ -88,10 +105,17 @@ class ImportRecipe(GenericBaseRecipe): ...@@ -88,10 +105,17 @@ class ImportRecipe(GenericBaseRecipe):
Create a script to restore the database from 'custom' format. Create a script to restore the database from 'custom' format.
""" """
content = textwrap.dedent("""\ content = textwrap.dedent("""\
#!%(shell-binary)s \\ #!%(shell-binary)s
umask 077 \\ umask 077
cd ~/%(srv-directory)s/ ; \\ cd %(backup-directory)s;
tar -xzf %(backup-directory)s/runner.tgz runner/ ; \\ %(rsync-binary)s -avz --delete runner/ %(srv-directory)s/runner;
%(rsync-binary)s -avz etc/ %(etc-directory)s;
ifs=$IFS IFS=';'
read user pass remaining < %(etc-directory)s/.users
IFS=$ifs
trap 'rm -f login_cookie' EXIT
%(curl-binary)s -vg6L -F clogin="$user" -F cpwd="$pass" --dump-header login_cookie %(backend-url)s/doLogin;
%(curl-binary)s -vg6LX POST --cookie login_cookie --max-time 5 %(backend-url)s/runSoftwareProfile;
""" % self.options) """ % self.options)
self.createExecutable(wrapper, content=content) self.createExecutable(wrapper, content=content)
......
[buildout] [buildout]
extends = extends =
../../component/cloud9/buildout.cfg ../../component/cloud9/buildout.cfg
../../component/curl/buildout.cfg
../../component/dash/buildout.cfg ../../component/dash/buildout.cfg
../../component/dropbear/buildout.cfg ../../component/dropbear/buildout.cfg
../../component/git/buildout.cfg ../../component/git/buildout.cfg
...@@ -12,6 +13,7 @@ extends = ...@@ -12,6 +13,7 @@ extends =
../../stack/slapos.cfg ../../stack/slapos.cfg
parts = parts =
rdiff-backup
template template
slapos-cookbook slapos-cookbook
eggs eggs
......
...@@ -11,8 +11,11 @@ parts += ...@@ -11,8 +11,11 @@ parts +=
recipe = slapos.cookbook:slaprunner.export recipe = slapos.cookbook:slaprunner.export
wrapper = $${directory:bin}/$${slap-parameter:namebase}-exporter wrapper = $${directory:bin}/$${slap-parameter:namebase}-exporter
srv-directory = $${directory:srv} srv-directory = $${directory:srv}
etc-directory = $${directory:etc}
backup-directory = $${directory:backup} backup-directory = $${directory:backup}
shell-binary = ${dash:location}/bin/dash shell-binary = ${dash:location}/bin/dash
rsync-binary = ${rsync:location}/bin/rsync
# Extends publish section with resilient parameters # Extends publish section with resilient parameters
[urls] [urls]
......
...@@ -10,7 +10,11 @@ parts += ...@@ -10,7 +10,11 @@ parts +=
[importer] [importer]
recipe = slapos.cookbook:slaprunner.import recipe = slapos.cookbook:slaprunner.import
wrapper = $${directory:bin}/$${slap-parameter:namebase}-exporter wrapper = $${directory:bin}/$${slap-parameter:namebase}-importer
srv-directory = $${directory:srv} srv-directory = $${directory:srv}
etc-directory = $${directory:etc}
backup-directory = $${directory:backup} backup-directory = $${directory:backup}
shell-binary = ${dash:location}/bin/dash shell-binary = ${dash:location}/bin/dash
\ No newline at end of file rsync-binary = ${rsync:location}/bin/rsync
curl-binary = ${curl:location}/bin/curl
backend-url = $${slaprunner:access-url}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment