Subject: bug#47704: closed (Re: [bug#47704] [PATCH] services: mysql: Add extra-environment as configuration option.)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 13 Apr 2021 17:00:02 +0000

Your bug report

#47704: [PATCH] services: mysql: Add extra-environment as configuration option.

which was filed against the guix-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
47704: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=47704
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: [bug#47704] [PATCH] services: mysql: Add extra-environment as configuration option.
From: Leo Prikler <[email-masked]>
To: Maxime Devos <[email-masked]>, david larsson <[email-masked]>
Cc: [email-masked]
Date: Tue, 13 Apr 2021 18:58:57 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Am Montag, den 12.04.2021, 22:09 +0200 schrieb Maxime Devos:
> I think your original patch is good to go into the git repo.  I'll
> open a
> separate bug report about ‘absolutising’ the binaries referred to
> from the scripts.
I've pushed this patch now, but let us still look for a smaller
solution if applicable.  (That said, I'm not a mysql user and I'm happy
to leave security stuff to lle_bout.)

@david: Note, that I did not change the author, meaning it is committed
as "methuselah-0 <[email-masked]>" rather than 
"david larsson <[email-masked]>".  Since this patch is
hopefully small enough to not require attribution, that is fine, but if
you plan on making bigger changes, please consider setting your git up
appropriately.

Regards,
Leo 

Subject: [PATCH] services: mysql: Add extra-environment as configuration option.
From: david larsson <[email-masked]>
To: [email-masked]
Date: Sun, 11 Apr 2021 10:44:43 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi!
This patch is needed for the Galera add-on to MariaDB, which runs some 
scripts like for example wsrep_sst_rsync that needs access to additional 
binaries in PATH.

I tested the patch with (and without) below snippets to the 
mysql-service in my config.scm and successfully connected to a 
MariaDB/Galera cluster.

I ran these commands to test:
guix pull --url=/home/user1/src/guix --profile=/tmp/guix.master 
--disable-authentication --allow-downgrades ; 
GUIX_PROFILE="/tmp/guix.master" ; . "$GUIX_PROFILE/etc/profile" ; guix 
system reconfigure config.scm --fallback --allow-downgrades

------------------------------------------------------------------

(extra-environment #~(list (string-append "PATH=/usr/bin:/bin:" #$rsync 
"/bin:" #$coreutils "/bin:" #$gawk "/bin:" #$grep "/bin:" #$mariadb 
"/bin:" #$iproute "/sbin:" 
"/run/setuid-programs:/run/current-system/profile/bin:/run/current-system/profile/sbin" 
) (string-append "SHELL=" #$bash) "USER=mysql" 
"SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt" 
"SSL_CERT_DIR=/run/current-system/profile/etc/ssl/certs"))

(extra-content #~(string-append "log_error=/var/lib/mysql/log_error.log
# 
https://www.percona.com/blog/2017/07/26/what-is-innodb_autoinc_lock_mode-and-why-should-i-care/
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2

# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=" #$galera "/lib/libgalera_smm.so

# Galera Cluster Configuration
wsrep_cluster_name=\"test_cluster\"
wsrep_cluster_address=\"gcomm://redacted,redacted\"
# according to 
https://galeracluster.com/library/documentation/mysql-wsrep-options.html
# leaving it empty starts a new cluster, so you should immediately 
reconfigure again after doing this.
#wsrep_cluster_address=\"gcomm://\"

# Galera Synchronization Configuration
wsrep_sst_method=rsync

# Galera Node Configuration
wsrep_node_address=\"redacted\"
wsrep_node_name=\"librem13v3guixsd\""))
                                ))

------------------------------------------------------------------

Please someone also review [bug#47517] [PATCH] gnu: nginx: Enable stream 
module

which adds support for tcp loadbalancing that can be used to scale a 
MariaDB/Galera cluster.

Best regards,
David

From 927444652f4b774928de78c1558b4e942abff203 Mon Sep 17 00:00:00 2001
From: methuselah-0 <[email-masked]>
Date: Sun, 11 Apr 2021 10:30:01 +0200
Subject: [PATCH] services: mysql: Add extra-environment as configuration
 option.

* gnu/services/databases.scm (mysql-configuration): Add extra-environment
(mysql-service): Use #:log-file and #:environment-variables

* doc/guix.texi: Document it.
---
 doc/guix.texi              | 3 +++
 gnu/services/databases.scm | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index c23d044ff5..298585a695 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -19809,6 +19809,9 @@ Socket file to use for local (non-network) connections.
 @item @code{extra-content} (default: @code{""})
 Additional settings for the @file{my.cnf} configuration file.
 
+@item @code{extra-environment} (default: @code{#~'()})
+List of environment variables passed to the @command{mysqld} process.
+
 @item @code{auto-upgrade?} (default: @code{#t})
 Whether to automatically run @command{mysql_upgrade} after starting the
 service.  This is necessary to upgrade the @dfn{system schema} after
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index a841e7a50e..8d266c1cba 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2018 Julien Lepiller <[email-masked]>
 ;;; Copyright © 2019 Robert Vollmert <[email-masked]>
 ;;; Copyright © 2020 Marius Bakke <[email-masked]>
+;;; Copyright © 2021 David Larsson <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -527,6 +528,7 @@ created after the PostgreSQL database is started.")))
   (port mysql-configuration-port (default 3306))
   (socket mysql-configuration-socket (default "/run/mysqld/mysqld.sock"))
   (extra-content mysql-configuration-extra-content (default ""))
+  (extra-environment mysql-configuration-extra-environment (default #~'()))
   (auto-upgrade? mysql-configuration-auto-upgrade? (default #t)))
 
 (define %mysql-accounts
@@ -611,11 +613,14 @@ FLUSH PRIVILEGES;
          (provision '(mysql))
          (documentation "Run the MySQL server.")
          (start (let ((mysql  (mysql-configuration-mysql config))
+                      (extra-env (mysql-configuration-extra-environment config))
                       (my.cnf (mysql-configuration-file config)))
                   #~(make-forkexec-constructor
                      (list (string-append #$mysql "/bin/mysqld")
                            (string-append "--defaults-file=" #$my.cnf))
-                     #:user "mysql" #:group "mysql")))
+                           #:user "mysql" #:group "mysql"
+                           #:log-file "/var/log/mysqld.log"
+                           #:environment-variables #$extra-env)))
          (stop #~(make-kill-destructor)))))
 
 (define (mysql-upgrade-wrapper mysql socket-file)
-- 
2.30.2