From 6f11404d3f7feb8b57ff99c35cc6041dd58f3824 Mon Sep 17 00:00:00 2001
From: Tristan Cavelier <tristan.cavelier@tiolive.com>
Date: Mon, 20 Oct 2014 15:40:23 +0000
Subject: [PATCH] erp5 stack: fix mariadb host blocking

- Use latest slapos.toolbox (0.41.0)
- stack/erp5/buildout.cfg add script is-local-tcp-port-opened
- Change instance-mariadb promise to use is-local-tcp-port-opened

The monitor runs promises every 5 minutes.
The previous mariadb promise check for listening tcp port by openning
a socket and closing it, causing mariadb to block the host after a
defined amount of time.

The new script `is-local-tcp-port-opened` checks for opened tcp port
on current machine by reading /proc/net/tcp{,6}. No socket is opened.
Maria should not block hosts anymore.
---
 stack/erp5/buildout.cfg            | 7 ++++---
 stack/erp5/instance-mariadb.cfg.in | 8 ++++----
 stack/erp5/instance.cfg.in         | 1 +
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/stack/erp5/buildout.cfg b/stack/erp5/buildout.cfg
index 0ff660517..0d8be9e6c 100644
--- a/stack/erp5/buildout.cfg
+++ b/stack/erp5/buildout.cfg
@@ -159,7 +159,7 @@ context =
 [template-mariadb]
 < = download-base
 filename = instance-mariadb.cfg.in
-md5sum = 85826f72b4eac9cbaea2d34d73e6d445
+md5sum = 99a9e71b599def71322c86c0bd02a21e
 link-binary =
   ${coreutils:location}/bin/basename
   ${coreutils:location}/bin/cat
@@ -217,7 +217,7 @@ md5sum = e40e2e39f4941c6372f4357e8589a5cf
 # XXX: "template.cfg" is hardcoded in instanciation recipe
 filename = template.cfg
 template = ${:_profile_base_location_}/instance.cfg.in
-md5sum = 8ccd836753a44aa26d68f5fff00c2eff
+md5sum = ffe07d9516691dd57014e5af73b7443e
 extra-context =
     key mariadb_link_binary template-mariadb:link-binary
     key zope_link_binary template-zope:link-binary
@@ -589,6 +589,7 @@ eggs =
   slapos.toolbox[zodbpack]
 
 scripts =
+  is-local-tcp-port-opened
   killpidfromfile
   onetimedownload
   zodbpack
@@ -695,7 +696,7 @@ restkit = 4.2.2
 rtjp-eventlet = 0.3.2
 slapos.recipe.build = 0.12
 slapos.recipe.template = 2.5
-slapos.toolbox = 0.40.2
+slapos.toolbox = 0.41.0
 smmap = 0.8.2
 socketpool = 0.5.3
 spyne = 2.11.0
diff --git a/stack/erp5/instance-mariadb.cfg.in b/stack/erp5/instance-mariadb.cfg.in
index 042ed143e..f5923e49f 100644
--- a/stack/erp5/instance-mariadb.cfg.in
+++ b/stack/erp5/instance-mariadb.cfg.in
@@ -213,10 +213,10 @@ log = ${:var}/log
 run = ${:var}/run
 
 [promise]
-recipe = slapos.cookbook:check_port_listening
-path = ${directory:promise}/mariadb
-hostname = ${my-cnf-parameters:ip}
-port = ${my-cnf-parameters:port}
+recipe = slapos.cookbook:wrapper
+command-line = "{{ parameter_dict['bin-directory'] }}/is-local-tcp-port-opened" "${my-cnf-parameters:ip}" "${my-cnf-parameters:port}"
+wrapper-path = ${directory:promise}/mariadb
+parameters-extra = true
 
 [buildout]
 extends =
diff --git a/stack/erp5/instance.cfg.in b/stack/erp5/instance.cfg.in
index 5e9c3e6f5..906fe034b 100644
--- a/stack/erp5/instance.cfg.in
+++ b/stack/erp5/instance.cfg.in
@@ -188,6 +188,7 @@ template-my-cnf = {{ template_my_cnf }}
 template-mariadb-initial-setup = {{ template_mariadb_initial_setup }}
 link-binary = {{ dumps(mariadb_link_binary) }}
 instance-logrotate-cfg = {{ template_logrotate_base }}
+bin-directory = {{ bin_directory }}
 
 [dynamic-template-mariadb]
 < = jinja2-template-base
-- 
2.30.9