From 5954d31217405f1d9dc8c8e0c74d9130b029bb6f Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Tue, 31 Jan 2017 18:06:06 +0900
Subject: [PATCH] stack.erp5: Make etc/run/mariadb accept extra arguments.

Will be needed to customise backup restoration.
Also, stop using slapos.cookbook:generic.mysql.wrap_mysqld, which:
- did not allow extra arguments
- did incorrect and superfluous ulimit manipulation
---
 stack/erp5/buildout.hash.cfg       |  2 +-
 stack/erp5/instance-mariadb.cfg.in | 25 ++++++++++++++++---------
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/stack/erp5/buildout.hash.cfg b/stack/erp5/buildout.hash.cfg
index 66b705f89..0addcb26f 100644
--- a/stack/erp5/buildout.hash.cfg
+++ b/stack/erp5/buildout.hash.cfg
@@ -19,7 +19,7 @@ md5sum = 372e5247d0a1514f3406228407b10d77
 
 [template-mariadb]
 filename = instance-mariadb.cfg.in
-md5sum = 22270cd739fe00c45d0605dfb7edd2eb
+md5sum = 9ee9c331b2d4f81f85c3ef47af0e6d4a
 
 [template-kumofs]
 filename = instance-kumofs.cfg.in
diff --git a/stack/erp5/instance-mariadb.cfg.in b/stack/erp5/instance-mariadb.cfg.in
index c8f017d39..a50cd4e0e 100644
--- a/stack/erp5/instance-mariadb.cfg.in
+++ b/stack/erp5/instance-mariadb.cfg.in
@@ -155,14 +155,22 @@ mysql = ${binary-wrap-mysql:wrapper-path}
 init-script = ${init-script:rendered}
 mysql_tzinfo_to_sql = ${binary-wrap-mysql_tzinfo_to_sql:wrapper-path}
 
-[mysqld]
-recipe = slapos.cookbook:generic.mysql.wrap_mysqld
-output = ${directory:services}/mariadb
-binary = {{ parameter_dict['mariadb-location'] }}/bin/mysqld
-configuration-file = ${my-cnf:rendered}
-data-directory = ${my-cnf-parameters:data-directory}
-mysql-install-binary = {{ parameter_dict['mariadb-location'] }}/scripts/mysql_install_db
-mysql-base-directory = {{ parameter_dict['mariadb-location'] }}
+[{{ section('mysqld') }}]
+< = jinja2-template-executable
+# Note: all rendering is done when this file is rendered, not when the mysqld
+# section is installed - so I only use jinja2 as a fancy way to write an
+# executable file with partition-dependent but instance-parameters independent
+# content.
+template = inline:#!{{ parameter_dict['dash-location'] }}/bin/dash
+  '{{ parameter_dict['mariadb-location'] }}/scripts/mysql_install_db' \
+    --defaults-file='${my-cnf:rendered}' \
+    --skip-name-resolve \
+    --datadir='${my-cnf-parameters:data-directory}' \
+    --basedir='{{ parameter_dict['mariadb-location'] }}' \
+  && exec '{{ parameter_dict['mariadb-location'] }}/bin/mysqld' \
+    --defaults-file='${my-cnf:rendered}' \
+    "$@"
+rendered = ${directory:services}/mariadb
 
 [logrotate-entry-mariadb]
 recipe = slapos.cookbook:logrotate.d
@@ -257,7 +265,6 @@ parts +=
   logrotate-entry-mariadb
   binary-link
   update-mysql
-  mysqld
   resiliency-exclude-file
   resiliency-after-import-script
   promise
-- 
2.30.9