From unknown Fri Sep 12 04:45:15 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#49155] [PATCH] gnu: mysql: Support custom data dir. Resent-From: Aljosha Papsch Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 21 Jun 2021 14:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49155 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49155@debbugs.gnu.org Cc: Ellen Papsch X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162428535230831 (code B ref -1); Mon, 21 Jun 2021 14:23:01 +0000 Received: (at submit) by debbugs.gnu.org; 21 Jun 2021 14:22:32 +0000 Received: from localhost ([127.0.0.1]:36760 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lvKon-000817-Au for submit@debbugs.gnu.org; Mon, 21 Jun 2021 10:22:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:39148) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lvK5E-0006Re-Ac for submit@debbugs.gnu.org; Mon, 21 Jun 2021 09:35:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvK5D-0002Vq-Td for guix-patches@gnu.org; Mon, 21 Jun 2021 09:35:24 -0400 Received: from mail-fr2deu01on2070c.outbound.protection.outlook.com ([2a01:111:f400:7e24::70c]:62433 helo=DEU01-FR2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvK59-00023q-Qn for guix-patches@gnu.org; Mon, 21 Jun 2021 09:35:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SvinxU57k6FRiv/9xPTyl3U7oZGqNPnZybSvxx13ranv5+FqYZVxhm2IpMd6TsrIbg+pWaK5qnrc9JjNHU9A9+Sb5o+1oCMAwceFMdynv+BcZbt+7Gm//mIunLqphKjxAyZ1AN1MCIxpNtvhjQkAWOR7jSMM97lAup/RD4voRy2KDq9xfg/kwvtqCblOxaKEKSpaox1WeLC1xNXrTBAOLivezVunQzaj6nNwP3aW9TkqYI7m8yzTCAkqZWcmfktoNWQU9mEjshr6wOJOpewFAFjXEIJ/NAfODSebwXSVCyKVtOOqc4axD3jxQaXFWGeBHgkoPRwI1gctkZd1cl/iDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GjfEcNf2tuY/UaRFMWgO1Hqs66G7wYyMCVc2eiCCEU0=; b=DzTkkmFAkNXgOZA0/ZtG0BNQ4OU689FKoJKp1s4b47H4OmsFSoVIx7qIeK1hj5RaUo1yg/4Ok2QTPBtnkKnaLVgVLZ/D/znVMB6gn44z1FM1R3wkU9Eh1LoYi2MbhTUE+kY+R8fYGkeX+WzMJgsJI5lFIHQV+XtQqYrs/jFDGJyPjw5ID8ceywT46abcVVVn+PT/hWCfLG0xN3fwwFhmujP74SeQB7NF5XW4Cq1ugJHz9c+ORxZKdqxRE7qwbGrhmSh75QIHNQoRgScgc93z3qyWTHSAVKXZfvZ2txvKZgDp/Xu7bCy68T+PsROIVrzUqg+b4lkf6PasnCcnxvkq6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stern-data.com; dmarc=pass action=none header.from=stern-data.com; dkim=pass header.d=stern-data.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sternasset.onmicrosoft.com; s=selector1-sternasset-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GjfEcNf2tuY/UaRFMWgO1Hqs66G7wYyMCVc2eiCCEU0=; b=ViWJxT6sKI3fDAszADk25ce/ap1tPtuMmy80/Tt6Unk5ZqJMmf/vfn61vq+NnBVNT/EWs+SdTEDhDAWBfV3BObrHFlSca4ApH8S+f5u3bFjONYDrr9McS3esdt4jaik8gYC/46qo4KZj462cRIJTYvBGHDA9hEv80zKwZiMd6EBJEnxWtok0TCwuIOO/aOq98hVGmhNBn4bfSHy/sLTGqtHM56oYLpSdkXpkKRVIQzIxbbGI+ynmEz0+L++wRDo6J8z66cjYzqXZbPMdY9hM2hT7ZM5u3AWoPjw9UUvZUO9c/TKTCLfcELuNqo6FrcZSrQl9JVkI3d8g0ygbXBaMNA== Authentication-Results: gnu.org; dkim=none (message not signed) header.d=none;gnu.org; dmarc=none action=none header.from=stern-data.com; Received: from BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:f::11) by BEXP281MB0071.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.10; Mon, 21 Jun 2021 13:30:12 +0000 Received: from BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM ([fe80::69c4:db1b:2158:34d8]) by BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM ([fe80::69c4:db1b:2158:34d8%5]) with mapi id 15.20.4264.016; Mon, 21 Jun 2021 13:30:12 +0000 From: Aljosha Papsch Date: Mon, 21 Jun 2021 15:27:52 +0200 Message-Id: <20210621132750.49528-1-ep@stern-data.com> X-Mailer: git-send-email 2.32.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: PR3P251CA0022.EURP251.PROD.OUTLOOK.COM (2603:10a6:102:b5::18) To BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:f::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (2a02:908:c39:9d60:ec9b:bd9a:f3b7:625d) by PR3P251CA0022.EURP251.PROD.OUTLOOK.COM (2603:10a6:102:b5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16 via Frontend Transport; Mon, 21 Jun 2021 13:30:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 350ff8a7-925a-490f-3758-08d934b8b231 X-MS-TrafficTypeDiagnostic: BEXP281MB0071: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I6bxCHjq6H4roPm4UvQ48DRyvVV6cdyhHswzr5NkRrc3mlEr/wEYV4OGL06g5pmCh5/pyh9tjRulIImw8izAe0NFVqQFVb4IpqrohmeZUPCJtENWKToxbEIZslmjpRY3fybpMF7OpXx6cxWRwxjZuMbGS703igQcIPs/KvlDCVb2Iw+idITYNf+T972x2dZe7EhqBwJDb0UMWzbzzQEgCDsiwIuzr/xqhqxq5sZ8reizEFF/m0LRU4oy5UeH/sZoG3R15gQkFG6syCC9NaxFiopjgrla3SzVJModqpPbjz8UUth/ZIho7t3m2YyDynIq9Sq7bDlpNSXjrqxDxi/xAzsm8NEmUbidDUCWhrNSo3cLvQPxd27kvvIvLcKQFyLQQTYYEYuzGDf97cRjhtSiseSr1U4zhz92HIlGopRG9zJcxUDMh95ZW4OJOr/e7/lV/ZjXm0yy99h8Dtb+7izZPPaS33sh9ZSJmTWsN4V/hUJ9ofk2h/aOP3Y3ynFIdZ738jCCwwy/oJLsqhfaoN+EC88lXdOYGBqy7Do85B/ZhrD7OsPpYc9UJl9/sWzWhvm52NCRii4XHl1sosxQhsa9IEP2Shdh2IKYDSRdgwv8aSD7at1iAhNr3YuyPZsPifoWvNggPsjHqb+SV2Yk0pBPKw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(4636009)(396003)(136003)(39830400003)(346002)(366004)(376002)(38100700002)(86362001)(83380400001)(2906002)(6916009)(52116002)(6506007)(66556008)(66946007)(186003)(4326008)(36756003)(8936002)(1076003)(6512007)(6486002)(2616005)(107886003)(478600001)(8676002)(316002)(5660300002)(66476007)(6666004)(21314003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mQzR+GN1rxa4P1GMTydVCFVdF4h2vLdGa4IuBBvjNH1niDrLtPpYCIi4S3PPGr55F8f9J2+eQ4lrgBTIGx3MKNcak7ww01Rj3kqiT6Jo6X77WdgeC46Iq1eNenwoyrKEhzWTGPvEYZKoJrKZzFWn7pVAH0PgC6i+s6htdzyZvyIFx+H8QKh2JJy1WoTdkV6Cu+Rz1Zd5LPayRFUJKmJgogftQbG3HUy/oQTFMXIpasVNy6eySkVOBpFRuykzyhMtLziIv5CBbOjr/VahePQJilRs2K7dAG2YPMULHnY33cz+MT1W6tNe+CvU/Qy0k5plyvawgakkwOAcLJFMemsM10dlTMs7U/I4g1dfWkXMy1asjKY1tZUm+G+DQ70Vh3aWWFV2KZlrI7MQF/FyVPZ7EpzhYEOG3Dvg8hGTA0oArCBwdpBDFQL31IWmoDyB57G7A5Aymys6wcPBXjVl2T6jBKu1pRAxLwow1Z+GW+ryTOXE2YB1qhl09KO+4CNQC16Y4kBC5ynpUfWge/PW65Jq6JFj7zXjXH1NxlMKj+0eUJ9+8pXZOJhZHpVMYnQm0OWLxSAGWZPLU6QBWDtrKhAeQA+Lrd5OO/HafZuvaScQOQpvFXu9uBxgy2MrsltEQPLMgITt6kH/EQ/1et8M+JeoUTJFv8f7937eJJy+5GqdBV+RROfSvWj7ih0n8BlOqQzE3RpTj+KTjSbweK39rdtIEWgswkc0iXT66qQMkDnB4kjTm9FlvkB6ouvlJv2HQyhadxb5SyIth7kqj+rODPz72oBSkxiUn1ArQ1q19AXx+My/nBz3u3ptJbL5Jvkhyxq/Po1xiOKdG8hic7JHs5BzSvk/h4PmfoHTNk5CVyq1qUE1nXfSjiXytMcqS/JK/fHBT0fYtb9RYxpn0aeMFTwA6qBRHRoMcdegnFc+UZW1Hysm7wVHfrbs63bENEmXJpDffJFv04EhUCaMhIWYauvIlRBNW9wmspkpWziAiuKxoqkkNajFrpdvKZqxkeY8gOSRcFk+vFi4vfSfnLCqGppmSyWwMRdBesBlULjH//Vl5zuGGaeAePxRHo8tVCv7YX6P+KU9eBf6kdGJbIx+RHjepLOFlIrSQAlSYXDzwtpKAdj8XCPnka6h/+VoCqdq3yT2i72YD0tdWfhF0JT1aH35Px+qgvcpB4o+14YuHoO98JDNA15UUcxvZaxIPowF1cX2EJuXKEmjs3FOMY5QPfRIL2kGDUvj1b0x2romwYXMgKiRdOd3QvXMmSDKbgo0G8vi4c6d/NUTNZMcW42zjiabR/X0RsMGaTdas88uAXk682Wm7i4gpP4hXPy6ay/3mxEPmjZgquHd0KA7jSWCCH+HAkko/pyjDEnrEJdjqRgdvn+gYLikBmVNIYf7F98xEwA+ X-OriginatorOrg: stern-data.com X-MS-Exchange-CrossTenant-Network-Message-Id: 350ff8a7-925a-490f-3758-08d934b8b231 X-MS-Exchange-CrossTenant-AuthSource: BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2021 13:30:12.0401 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e55b1d7b-b6d7-445f-a720-8de54d4464ac X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: us7dtVoZk01a8kagDDb0AoENyZL45OXfQZZ6mB+aG+KpJOCCK/5/vsEK71yPBEq5ElJLfKXjkJt14+nw6/ki/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BEXP281MB0071 Received-SPF: pass client-ip=2a01:111:f400:7e24::70c; envelope-from=ep@stern-data.com; helo=DEU01-FR2-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, MSGID_FROM_MTA_HEADER=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.6 (/) X-Mailman-Approved-At: Mon, 21 Jun 2021 10:22:28 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.4 (/) From: Ellen Papsch * gnu/services/databases.scm (mysql-configuration): Add datadir property. * gnu/services/databases.scm (mysql-configuration-file): Replace hard coded data dir with property from config. * gnu/services/databases.scm (%mysql-activation): Remove activation, it runs before PID 1. The data dir may reside on a file system not mounted at this time. * gnu/services/databases.scm (mysql-install-shepherd-service): Create service which replaces the activation. Provide mysql-install. * gnu/services/databases.scm (mysql-shepherd-service): Move invocation of mysqld to mysql-start program-file, because the invocation gotten more complex. Require mysql-install. * gnu/services/databases.scm (mysql-start): Invoke mysqld only if a lock file appears. * gnu/services/databases.scm (mysql-shepherd-services): Prepend the install service before the normal service. * gnu/services/databases.scm (mysql-upgrade-wrapper): Increase timeout to 20s to let the mysql install procedure finish. --- gnu/services/databases.scm | 187 +++++++++++++++++++++++-------------- 1 file changed, 119 insertions(+), 68 deletions(-) diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm index eba88cdb68..f8f78619d3 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -8,6 +8,7 @@ ;;; Copyright © 2019 Robert Vollmert ;;; Copyright © 2020 Marius Bakke ;;; Copyright © 2021 David Larsson +;;; Copyright © 2021 Aljosha Papsch ;;; ;;; This file is part of GNU Guix. ;;; @@ -527,6 +528,7 @@ created after the PostgreSQL database is started."))) (bind-address mysql-configuration-bind-address (default "127.0.0.1")) (port mysql-configuration-port (default 3306)) (socket mysql-configuration-socket (default "/run/mysqld/mysqld.sock")) + (datadir mysql-configuration-datadir (default "/var/lib/mysql")) (extra-content mysql-configuration-extra-content (default "")) (extra-environment mysql-configuration-extra-environment (default #~'())) (auto-upgrade? mysql-configuration-auto-upgrade? (default #t))) @@ -544,85 +546,133 @@ created after the PostgreSQL database is started."))) (define mysql-configuration-file (match-lambda - (($ mysql bind-address port socket extra-content) + (($ mysql bind-address port socket datadir extra-content) (mixed-text-file "my.cnf" "[mysqld] -datadir=/var/lib/mysql +datadir=" datadir " socket=" socket " bind-address=" bind-address " port=" (number->string port) " " extra-content " ")))) -(define (%mysql-activation config) - "Return an activation gexp for the MySQL or MariaDB database server." - (let ((mysql (mysql-configuration-mysql config)) - (my.cnf (mysql-configuration-file config))) - #~(begin - (use-modules (ice-9 popen) - (guix build utils)) - (let* ((mysqld (string-append #$mysql "/bin/mysqld")) - (user (getpwnam "mysql")) - (uid (passwd:uid user)) - (gid (passwd:gid user)) - (datadir "/var/lib/mysql") - (rundir "/run/mysqld")) - (mkdir-p datadir) - (chown datadir uid gid) - (mkdir-p rundir) - (chown rundir uid gid) - ;; Initialize the database when it doesn't exist. - (when (not (file-exists? (string-append datadir "/mysql"))) - (if (string-prefix? "mysql-" (strip-store-file-name #$mysql)) - ;; For MySQL. - (system* mysqld - (string-append "--defaults-file=" #$my.cnf) - "--initialize" - "--user=mysql") - ;; For MariaDB. - ;; XXX: The 'mysql_install_db' script doesn't work directly - ;; due to missing 'mkdir' in PATH. - (let ((p (open-pipe* OPEN_WRITE mysqld - (string-append - "--defaults-file=" #$my.cnf) - "--bootstrap" - "--user=mysql"))) - ;; Create the system database, as does by 'mysql_install_db'. - (display "create database mysql;\n" p) - (display "use mysql;\n" p) - (for-each - (lambda (sql) - (call-with-input-file - (string-append #$mysql:lib "/share/mysql/" sql) - (lambda (in) (dump-port in p)))) - '("mysql_system_tables.sql" - "mysql_performance_tables.sql" - "mysql_system_tables_data.sql" - "fill_help_tables.sql")) - ;; Remove the anonymous user and disable root access from - ;; remote machines, as does by 'mysql_secure_installation'. - (display " -DELETE FROM user WHERE User=''; -DELETE FROM user WHERE User='root' AND - Host NOT IN ('localhost', '127.0.0.1', '::1'); -FLUSH PRIVILEGES; -" p) - (close-pipe p)))))))) +(define (mysql-with-install-lock) + "Return a loop function which evals thunk when the install is locked." + #~(lambda (thunk) + (let loop ((i 0)) + (let ((timeout 10) + (lock-stat (stat "/var/lib/mysql.lock" #f))) + (if (and (not (eq? lock-stat #f)) + (eq? (stat:type lock-stat) 'regular)) + (apply thunk '()) + (if (< i timeout) + (begin + (sleep 1) + (loop (+ 1 i))) + (throw 'timeout-error + "MySQL installation not locked in time!"))))))) + +(define (mysql-start config) + "Start mysqld if install lock file appears" + (program-file + "mysql-start" + (let ((mysql (mysql-configuration-mysql config)) + (my.cnf (mysql-configuration-file config))) + #~(let ((mysqld (string-append #$mysql "/bin/mysqld")) + (with-lock #$(mysql-with-install-lock))) + (with-lock (lambda () + (execl mysqld mysqld + (string-append "--defaults-file=" #$my.cnf)))))))) (define (mysql-shepherd-service config) (list (shepherd-service (provision '(mysql)) + (requirement '(mysql-install)) (documentation "Run the MySQL server.") - (start (let ((mysql (mysql-configuration-mysql config)) + (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" - #:log-file "/var/log/mysqld.log" - #:environment-variables #$extra-env))) + (list #$(mysql-start config)) + #:user "mysql" #:group "mysql" + #:log-file "/var/log/mysqld.log" + #:environment-variables #$extra-env))) (stop #~(make-kill-destructor))))) +(define (mysql-install config) + "Install MySQL system database and secure the installation." + (let ((mysql (mysql-configuration-mysql config)) + (my.cnf (mysql-configuration-file config)) + (datadir (mysql-configuration-datadir config)) + (extra-env (mysql-configuration-extra-environment config))) + (program-file + "mysql-install" + (with-imported-modules (source-module-closure + '((ice-9 popen) + (guix build utils))) + #~(begin + (use-modules (ice-9 popen) + (guix build utils)) + (let* ((mysqld (string-append #$mysql "/bin/mysqld")) + (user (getpwnam "mysql")) + (uid (passwd:uid user)) + (gid (passwd:gid user)) + (datadir #$datadir) + (rundir "/run/mysqld")) + (mkdir-p datadir) + (chown datadir uid gid) + (mkdir-p rundir) + (chown rundir uid gid) + ;; Initialize the database when it doesn't exist. + (when (not (file-exists? (string-append datadir "/mysql"))) + (if (string-prefix? "mysql-" (strip-store-file-name #$mysql)) + ;; For MySQL. + (system* mysqld + (string-append "--defaults-file=" #$my.cnf) + "--initialize" + "--user=mysql") + ;; For MariaDB. + ;; XXX: The 'mysql_install_db' script doesn't work directly + ;; due to missing 'mkdir' in PATH. + (let ((p (open-pipe* OPEN_WRITE mysqld + (string-append + "--defaults-file=" #$my.cnf) + "--bootstrap" + "--user=mysql"))) + ;; Create the system database, as does by 'mysql_install_db'. + (display "create database mysql;\n" p) + (display "use mysql;\n" p) + (for-each + (lambda (sql) + (call-with-input-file + (string-append #$mysql:lib "/share/mysql/" sql) + (lambda (in) (dump-port in p)))) + '("mysql_system_tables.sql" + "mysql_performance_tables.sql" + "mysql_system_tables_data.sql" + "fill_help_tables.sql")) + ;; Remove the anonymous user and disable root access from + ;; remote machines, as does by 'mysql_secure_installation'. + (display " +DELETE FROM user WHERE User=''; +DELETE FROM user WHERE User='root' AND + Host NOT IN ('localhost', '127.0.0.1', '::1'); +FLUSH PRIVILEGES; +" p) + (close-pipe p)))) + (call-with-output-file "/var/lib/mysql.lock" + (lambda (p) + (write #t p))))))))) + +(define (mysql-install-shepherd-service config) + (list (shepherd-service + (provision '(mysql-install)) + (requirement '(file-systems)) + (one-shot? #t) + (documentation "Install MySQL system database and secure installation.") + (start #~(make-forkexec-constructor + (list #$(mysql-install config)) + #:log-file "/var/log/mysqld-install.log"))))) + (define (mysql-upgrade-wrapper mysql socket-file) ;; The MySQL socket and PID file may appear before the server is ready to ;; accept connections. Ensure the socket is responsive before attempting @@ -631,7 +681,7 @@ FLUSH PRIVILEGES; "mysql-upgrade-wrapper" #~(begin (let ((mysql-upgrade #$(file-append mysql "/bin/mysql_upgrade")) - (timeout 10)) + (timeout 20)) (begin (let loop ((i 0)) (catch 'system-error @@ -663,11 +713,14 @@ FLUSH PRIVILEGES; (list #$(mysql-upgrade-wrapper mysql socket)) #:user "mysql" #:group "mysql")))))) + (define (mysql-shepherd-services config) - (if (mysql-configuration-auto-upgrade? config) - (append (mysql-shepherd-service config) + (let ((min-services (append (mysql-install-shepherd-service config) + (mysql-shepherd-service config)))) + (if (mysql-configuration-auto-upgrade? config) + (append min-services (mysql-upgrade-shepherd-service config)) - (mysql-shepherd-service config))) + min-services))) (define mysql-service-type (service-type @@ -675,8 +728,6 @@ FLUSH PRIVILEGES; (extensions (list (service-extension account-service-type (const %mysql-accounts)) - (service-extension activation-service-type - %mysql-activation) (service-extension shepherd-root-service-type mysql-shepherd-services))) (default-value (mysql-configuration)))) -- 2.32.0 From unknown Fri Sep 12 04:45:15 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Aljosha Papsch Subject: bug#49155: closed (Re: [bug#49155] [PATCH] gnu: mysql: Support custom data dir.) Message-ID: References: <8735ad1s5v.fsf@gnu.org> <20210621132750.49528-1-ep@stern-data.com> X-Gnu-PR-Message: they-closed 49155 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 49155@debbugs.gnu.org Date: Sun, 20 Nov 2022 16:57:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1668963422-6532-1" This is a multi-part message in MIME format... ------------=_1668963422-6532-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #49155: [PATCH] gnu: mysql: Support custom data dir. 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 49155@debbugs.gnu.org. --=20 49155: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D49155 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1668963422-6532-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 49155-done) by debbugs.gnu.org; 20 Nov 2022 16:56:27 +0000 Received: from localhost ([127.0.0.1]:44397 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1owncI-0001gX-K3 for submit@debbugs.gnu.org; Sun, 20 Nov 2022 11:56:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34734) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1owncF-0001gI-8q for 49155-done@debbugs.gnu.org; Sun, 20 Nov 2022 11:56:25 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ownc8-00023i-Da; Sun, 20 Nov 2022 11:56:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=n3Z+nH4f1/DDQALkB3iUN36rwnxmVcqgwFkv6LA7zLw=; b=kW8QUly5RqQJuoWIn473 3Ky/MnvDWg348ZkZPjVF6raqUR+4LqcJy4WOUXonmW4zgo5aSaU8//1Dv0gc7E4fYNmtflL7GkjcT hS3ZVKTj+4bXQmUrKU9CEg/nTOiwMca4Q6fsJV/dSu8VIPu/piEkGhI71d2F24n5Cd1uCtI1n6ieM K8UOdkKIPEkh2/GrdI9AaExrXEAZUJdHDrANTePRciwkaw8puLE7uPzUEj5Vv9IuUlRzUt9EfE0Zj 6MPi8WWpyQDL9yffLMNjNzZXuWFaeWw67qn8+LC/ptRg+sCk5DDBP16o8nZrkZkOS28Zl1gOFuQUz 9bl1sAbf/1eyvw==; Received: from [84.214.173.6] (helo=localhost) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ownc7-0001gZ-03; Sun, 20 Nov 2022 11:56:16 -0500 From: Marius Bakke To: Aljosha Papsch , 49155-done@debbugs.gnu.org Subject: Re: [bug#49155] [PATCH] gnu: mysql: Support custom data dir. In-Reply-To: <20210621132750.49528-1-ep@stern-data.com> References: <20210621132750.49528-1-ep@stern-data.com> Date: Sun, 20 Nov 2022 17:56:12 +0100 Message-ID: <8735ad1s5v.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 49155-done Cc: Ellen Papsch X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) --=-=-= Content-Type: text/plain Hi! Thanks for the patch, and sorry for the slooow response... Aljosha Papsch skriver: > From: Ellen Papsch > > * gnu/services/databases.scm (mysql-configuration): Add datadir property. > * gnu/services/databases.scm (mysql-configuration-file): Replace hard coded > data dir with property from config. > * gnu/services/databases.scm (%mysql-activation): Remove activation, it runs > before PID 1. The data dir may reside on a file system not mounted at this > time. > * gnu/services/databases.scm (mysql-install-shepherd-service): Create service > which replaces the activation. Provide mysql-install. > * gnu/services/databases.scm (mysql-shepherd-service): Move invocation of > mysqld to mysql-start program-file, because the invocation gotten more > complex. Require mysql-install. > * gnu/services/databases.scm (mysql-start): Invoke mysqld only if a lock file > appears. > * gnu/services/databases.scm (mysql-shepherd-services): Prepend the install > service before the normal service. > * gnu/services/databases.scm (mysql-upgrade-wrapper): Increase timeout to > 20s to let the mysql install procedure finish. I have finally applied this patch, along with a follow-up commit to make the mysql-upgrade service also work with a custom datadir. I also ended up dropping the 'mysql-install' service in favor of a mysqld wrapper script that calls the mysql-install script at startup when the "mysql" DB is missing. Pushed in c7b266fdf2754c139803c156677bf2828c78d072. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iIUEARYKAC0WIQRNTknu3zbaMQ2ddzTocYulkRQQdwUCY3pcLA8cbWFyaXVzQGdu dS5vcmcACgkQ6HGLpZEUEHegOAEA/qTvA4fe5RxpSNFI5DoHMXJCASE8BomO6YrC l16bqFoA/i6tv8oeiwZSL6GWHB8b+OzESmpwJ1Ttrs62uSHNmjwA =vz+R -----END PGP SIGNATURE----- --=-=-=-- ------------=_1668963422-6532-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 21 Jun 2021 14:22:32 +0000 Received: from localhost ([127.0.0.1]:36760 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lvKon-000817-Au for submit@debbugs.gnu.org; Mon, 21 Jun 2021 10:22:32 -0400 Received: from lists.gnu.org ([209.51.188.17]:39148) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lvK5E-0006Re-Ac for submit@debbugs.gnu.org; Mon, 21 Jun 2021 09:35:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvK5D-0002Vq-Td for guix-patches@gnu.org; Mon, 21 Jun 2021 09:35:24 -0400 Received: from mail-fr2deu01on2070c.outbound.protection.outlook.com ([2a01:111:f400:7e24::70c]:62433 helo=DEU01-FR2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvK59-00023q-Qn for guix-patches@gnu.org; Mon, 21 Jun 2021 09:35:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SvinxU57k6FRiv/9xPTyl3U7oZGqNPnZybSvxx13ranv5+FqYZVxhm2IpMd6TsrIbg+pWaK5qnrc9JjNHU9A9+Sb5o+1oCMAwceFMdynv+BcZbt+7Gm//mIunLqphKjxAyZ1AN1MCIxpNtvhjQkAWOR7jSMM97lAup/RD4voRy2KDq9xfg/kwvtqCblOxaKEKSpaox1WeLC1xNXrTBAOLivezVunQzaj6nNwP3aW9TkqYI7m8yzTCAkqZWcmfktoNWQU9mEjshr6wOJOpewFAFjXEIJ/NAfODSebwXSVCyKVtOOqc4axD3jxQaXFWGeBHgkoPRwI1gctkZd1cl/iDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GjfEcNf2tuY/UaRFMWgO1Hqs66G7wYyMCVc2eiCCEU0=; b=DzTkkmFAkNXgOZA0/ZtG0BNQ4OU689FKoJKp1s4b47H4OmsFSoVIx7qIeK1hj5RaUo1yg/4Ok2QTPBtnkKnaLVgVLZ/D/znVMB6gn44z1FM1R3wkU9Eh1LoYi2MbhTUE+kY+R8fYGkeX+WzMJgsJI5lFIHQV+XtQqYrs/jFDGJyPjw5ID8ceywT46abcVVVn+PT/hWCfLG0xN3fwwFhmujP74SeQB7NF5XW4Cq1ugJHz9c+ORxZKdqxRE7qwbGrhmSh75QIHNQoRgScgc93z3qyWTHSAVKXZfvZ2txvKZgDp/Xu7bCy68T+PsROIVrzUqg+b4lkf6PasnCcnxvkq6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stern-data.com; dmarc=pass action=none header.from=stern-data.com; dkim=pass header.d=stern-data.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sternasset.onmicrosoft.com; s=selector1-sternasset-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GjfEcNf2tuY/UaRFMWgO1Hqs66G7wYyMCVc2eiCCEU0=; b=ViWJxT6sKI3fDAszADk25ce/ap1tPtuMmy80/Tt6Unk5ZqJMmf/vfn61vq+NnBVNT/EWs+SdTEDhDAWBfV3BObrHFlSca4ApH8S+f5u3bFjONYDrr9McS3esdt4jaik8gYC/46qo4KZj462cRIJTYvBGHDA9hEv80zKwZiMd6EBJEnxWtok0TCwuIOO/aOq98hVGmhNBn4bfSHy/sLTGqtHM56oYLpSdkXpkKRVIQzIxbbGI+ynmEz0+L++wRDo6J8z66cjYzqXZbPMdY9hM2hT7ZM5u3AWoPjw9UUvZUO9c/TKTCLfcELuNqo6FrcZSrQl9JVkI3d8g0ygbXBaMNA== Authentication-Results: gnu.org; dkim=none (message not signed) header.d=none;gnu.org; dmarc=none action=none header.from=stern-data.com; Received: from BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:f::11) by BEXP281MB0071.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:3::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.10; Mon, 21 Jun 2021 13:30:12 +0000 Received: from BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM ([fe80::69c4:db1b:2158:34d8]) by BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM ([fe80::69c4:db1b:2158:34d8%5]) with mapi id 15.20.4264.016; Mon, 21 Jun 2021 13:30:12 +0000 From: Aljosha Papsch To: guix-patches@gnu.org Subject: [PATCH] gnu: mysql: Support custom data dir. Date: Mon, 21 Jun 2021 15:27:52 +0200 Message-Id: <20210621132750.49528-1-ep@stern-data.com> X-Mailer: git-send-email 2.32.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: PR3P251CA0022.EURP251.PROD.OUTLOOK.COM (2603:10a6:102:b5::18) To BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:f::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (2a02:908:c39:9d60:ec9b:bd9a:f3b7:625d) by PR3P251CA0022.EURP251.PROD.OUTLOOK.COM (2603:10a6:102:b5::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16 via Frontend Transport; Mon, 21 Jun 2021 13:30:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 350ff8a7-925a-490f-3758-08d934b8b231 X-MS-TrafficTypeDiagnostic: BEXP281MB0071: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I6bxCHjq6H4roPm4UvQ48DRyvVV6cdyhHswzr5NkRrc3mlEr/wEYV4OGL06g5pmCh5/pyh9tjRulIImw8izAe0NFVqQFVb4IpqrohmeZUPCJtENWKToxbEIZslmjpRY3fybpMF7OpXx6cxWRwxjZuMbGS703igQcIPs/KvlDCVb2Iw+idITYNf+T972x2dZe7EhqBwJDb0UMWzbzzQEgCDsiwIuzr/xqhqxq5sZ8reizEFF/m0LRU4oy5UeH/sZoG3R15gQkFG6syCC9NaxFiopjgrla3SzVJModqpPbjz8UUth/ZIho7t3m2YyDynIq9Sq7bDlpNSXjrqxDxi/xAzsm8NEmUbidDUCWhrNSo3cLvQPxd27kvvIvLcKQFyLQQTYYEYuzGDf97cRjhtSiseSr1U4zhz92HIlGopRG9zJcxUDMh95ZW4OJOr/e7/lV/ZjXm0yy99h8Dtb+7izZPPaS33sh9ZSJmTWsN4V/hUJ9ofk2h/aOP3Y3ynFIdZ738jCCwwy/oJLsqhfaoN+EC88lXdOYGBqy7Do85B/ZhrD7OsPpYc9UJl9/sWzWhvm52NCRii4XHl1sosxQhsa9IEP2Shdh2IKYDSRdgwv8aSD7at1iAhNr3YuyPZsPifoWvNggPsjHqb+SV2Yk0pBPKw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(4636009)(396003)(136003)(39830400003)(346002)(366004)(376002)(38100700002)(86362001)(83380400001)(2906002)(6916009)(52116002)(6506007)(66556008)(66946007)(186003)(4326008)(36756003)(8936002)(1076003)(6512007)(6486002)(2616005)(107886003)(478600001)(8676002)(316002)(5660300002)(66476007)(6666004)(21314003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bVF6UitHTjFyeGE0UDFHTVR5ZFZDRlZkRjRoMnZMZEdhNEl1QkJ2ak5IMW5p?= =?utf-8?B?RHJMdFBwWUNJaTRTM1BQR3I1NUY4ZjlKMitlUTRscmdCVElHeDNNS05jYWs3?= =?utf-8?B?d3cwMVJqM2txaVQ2Sm82WDc3V2RnZUM0NklxMWVOZW53b3lyS0VoeldUR1B2?= =?utf-8?B?RVlaS29KcktaekZXbjdwVkFIMFBnQzZpK3M2aHRkenladnlJRngrSDhRS2gy?= =?utf-8?B?Skp5MVdvVGRrVjZDdStSejFaZDVMUGF5UkZVSkttSmdvZ2Z0UWJHM0hVeS9v?= =?utf-8?B?UVRGTVhJcGFzVk55NmV5U2tWT0JwRlJ1eWt6eWhNdEx6aUl2NUNCYk9qci9W?= =?utf-8?B?YWhlUFFKaWxSczJLN2RBRzJZUE1VTEhuWTMzY3orTVQxVzZ0TmUrQ3ZVL1F5?= =?utf-8?B?MGs1cGx5dmF3Z2Fra3dPQWNMSkZNZW1zTTEwZGxUTXM3VS9JNGcxZGZXa1hN?= =?utf-8?B?eTFhc2pLWTF0WlVtK0crRFE3MFZoM2FXV0ZWMktabHJJN01RRi9GeVZQWjdF?= =?utf-8?B?cHpoWUVPRzNEdmc4aEdUQTBvQXJDQndkcEJERlFMMzFJV21vRHlCNTdHN0E1?= =?utf-8?B?QXlteXM2d2NQQlhqVmwyVDZqQkt1MXBSQXhMd293MVorR1crcnlUT1hFMllC?= =?utf-8?B?MXFobDA5S08rNENOUUMxNlk0a0JDNXlucFVmV2dlL1BXNjVKcTZKRmo3elhq?= =?utf-8?B?WEgxTnhsTUtqKzBlVUo5KzhwWFpPSmhaSHBWTVluUW0wT1dMeFNBR1daUExV?= =?utf-8?B?NlFCV0R0cktoQWVRQStMcmQ1T08vSGFmWnV2YVNjUU9RcHZGWHU5dUJ4Z3ky?= =?utf-8?B?TXJzbHRFUVBMTWdJVHQ2a0gvRVEvMWV0OE0rSmVvVVRKRnY4Zjc5MzdlSkp5?= =?utf-8?B?KzVHcWRCVitSUk9mU3ZXajdpaDBuOEJsT3FRekUzUnBUaitLVGpTYndlSzM5?= =?utf-8?B?cmR0SUVXZ3N3a2MwaVhUNjZxUU1rRG5CNGtqVG05Rmx2a0I2b3V2bEp2MkhR?= =?utf-8?B?eWhhZHhiNVN5SXRoN2txaityT0RQejcyb0JTa3hpVW4xQXJRMXExOUFYeCtN?= =?utf-8?B?eS9uQnozdTNwdEpiTDVKdmtoeXhxL1BvMXhpT0tkRzhoaWM3SkhzNUJ6U3Zr?= =?utf-8?B?L2g0UG1mb0hUTms1Q1Z5cTFxVUUxblhmU2ppWHl0TWNxUy9KSy9mSEJUMGZZ?= =?utf-8?B?dGI5Ull4cG4wYWVNRlR3QTZxQlJIUm9NY2RlZ25GYytVWlcxSHlzbTd3Vkhm?= =?utf-8?B?cmJzNjNiRU5FbVhKcERmZkpGdjA0RWhVQ2FNaElXWWF1dklsUkJOVzl3bXNw?= =?utf-8?B?a3BXemlBaXVLeG9xa2tOYWpGcnBkdktacXhrZVk4Z09TUmNGayt2Rmk0dmZT?= =?utf-8?B?Zm5MQ3FHcHBtU3lXd01SZEJlc0JsVUxqSC8vVmw1enVHR2FlQWVQeFJIbzh0?= =?utf-8?B?VkN2N1lYNlArS1U5ZUJmNmtkR0piSXgrUkhqZXBMT0ZsSXJTUUFsU1lYRHp3?= =?utf-8?B?dHBLQWRqOFhDUG5rYTZoLytWb0NxZHEzeVQyaTcyWUQwdGRXZmhGMEpUMWFI?= =?utf-8?B?MzVQeCtxZ3ZjcEI0bysxNFl1SG9POThKRE5BMTVVVWN4dlpheElQb3dGMWNY?= =?utf-8?B?MkVKdVhLRW1qczNGT01ZNVFQZlJJTDJrR0RVdmoxYjB4MnJvbXdZWE1nS2lS?= =?utf-8?B?ZE9kM1F2WE1tU0RLYmdvMEc4dmk0YzZkL05VVE5aTWNXNDJ6amlhYlIvWDBS?= =?utf-8?B?c01HYVRkYXM4OHVBWGs2ODJXbTdpNGdwUDRoWFB5NmF5LzNteEVQbWpaZ3F1?= =?utf-8?B?SGQwS0E3alNXQ0NIK0hBa2tvL3B5akRFbnJFSmRqcVJnZHZuK2dZTGlrQm1W?= =?utf-8?Q?NIYf7F98xEwA+?= X-OriginatorOrg: stern-data.com X-MS-Exchange-CrossTenant-Network-Message-Id: 350ff8a7-925a-490f-3758-08d934b8b231 X-MS-Exchange-CrossTenant-AuthSource: BE0P281MB0034.DEUP281.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jun 2021 13:30:12.0401 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e55b1d7b-b6d7-445f-a720-8de54d4464ac X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: us7dtVoZk01a8kagDDb0AoENyZL45OXfQZZ6mB+aG+KpJOCCK/5/vsEK71yPBEq5ElJLfKXjkJt14+nw6/ki/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BEXP281MB0071 Received-SPF: pass client-ip=2a01:111:f400:7e24::70c; envelope-from=ep@stern-data.com; helo=DEU01-FR2-obe.outbound.protection.outlook.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, MSGID_FROM_MTA_HEADER=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.6 (/) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 21 Jun 2021 10:22:28 -0400 Cc: Ellen Papsch X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.4 (/) From: Ellen Papsch * gnu/services/databases.scm (mysql-configuration): Add datadir property. * gnu/services/databases.scm (mysql-configuration-file): Replace hard coded data dir with property from config. * gnu/services/databases.scm (%mysql-activation): Remove activation, it runs before PID 1. The data dir may reside on a file system not mounted at this time. * gnu/services/databases.scm (mysql-install-shepherd-service): Create service which replaces the activation. Provide mysql-install. * gnu/services/databases.scm (mysql-shepherd-service): Move invocation of mysqld to mysql-start program-file, because the invocation gotten more complex. Require mysql-install. * gnu/services/databases.scm (mysql-start): Invoke mysqld only if a lock file appears. * gnu/services/databases.scm (mysql-shepherd-services): Prepend the install service before the normal service. * gnu/services/databases.scm (mysql-upgrade-wrapper): Increase timeout to 20s to let the mysql install procedure finish. --- gnu/services/databases.scm | 187 +++++++++++++++++++++++-------------- 1 file changed, 119 insertions(+), 68 deletions(-) diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm index eba88cdb68..f8f78619d3 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -8,6 +8,7 @@ ;;; Copyright © 2019 Robert Vollmert ;;; Copyright © 2020 Marius Bakke ;;; Copyright © 2021 David Larsson +;;; Copyright © 2021 Aljosha Papsch ;;; ;;; This file is part of GNU Guix. ;;; @@ -527,6 +528,7 @@ created after the PostgreSQL database is started."))) (bind-address mysql-configuration-bind-address (default "127.0.0.1")) (port mysql-configuration-port (default 3306)) (socket mysql-configuration-socket (default "/run/mysqld/mysqld.sock")) + (datadir mysql-configuration-datadir (default "/var/lib/mysql")) (extra-content mysql-configuration-extra-content (default "")) (extra-environment mysql-configuration-extra-environment (default #~'())) (auto-upgrade? mysql-configuration-auto-upgrade? (default #t))) @@ -544,85 +546,133 @@ created after the PostgreSQL database is started."))) (define mysql-configuration-file (match-lambda - (($ mysql bind-address port socket extra-content) + (($ mysql bind-address port socket datadir extra-content) (mixed-text-file "my.cnf" "[mysqld] -datadir=/var/lib/mysql +datadir=" datadir " socket=" socket " bind-address=" bind-address " port=" (number->string port) " " extra-content " ")))) -(define (%mysql-activation config) - "Return an activation gexp for the MySQL or MariaDB database server." - (let ((mysql (mysql-configuration-mysql config)) - (my.cnf (mysql-configuration-file config))) - #~(begin - (use-modules (ice-9 popen) - (guix build utils)) - (let* ((mysqld (string-append #$mysql "/bin/mysqld")) - (user (getpwnam "mysql")) - (uid (passwd:uid user)) - (gid (passwd:gid user)) - (datadir "/var/lib/mysql") - (rundir "/run/mysqld")) - (mkdir-p datadir) - (chown datadir uid gid) - (mkdir-p rundir) - (chown rundir uid gid) - ;; Initialize the database when it doesn't exist. - (when (not (file-exists? (string-append datadir "/mysql"))) - (if (string-prefix? "mysql-" (strip-store-file-name #$mysql)) - ;; For MySQL. - (system* mysqld - (string-append "--defaults-file=" #$my.cnf) - "--initialize" - "--user=mysql") - ;; For MariaDB. - ;; XXX: The 'mysql_install_db' script doesn't work directly - ;; due to missing 'mkdir' in PATH. - (let ((p (open-pipe* OPEN_WRITE mysqld - (string-append - "--defaults-file=" #$my.cnf) - "--bootstrap" - "--user=mysql"))) - ;; Create the system database, as does by 'mysql_install_db'. - (display "create database mysql;\n" p) - (display "use mysql;\n" p) - (for-each - (lambda (sql) - (call-with-input-file - (string-append #$mysql:lib "/share/mysql/" sql) - (lambda (in) (dump-port in p)))) - '("mysql_system_tables.sql" - "mysql_performance_tables.sql" - "mysql_system_tables_data.sql" - "fill_help_tables.sql")) - ;; Remove the anonymous user and disable root access from - ;; remote machines, as does by 'mysql_secure_installation'. - (display " -DELETE FROM user WHERE User=''; -DELETE FROM user WHERE User='root' AND - Host NOT IN ('localhost', '127.0.0.1', '::1'); -FLUSH PRIVILEGES; -" p) - (close-pipe p)))))))) +(define (mysql-with-install-lock) + "Return a loop function which evals thunk when the install is locked." + #~(lambda (thunk) + (let loop ((i 0)) + (let ((timeout 10) + (lock-stat (stat "/var/lib/mysql.lock" #f))) + (if (and (not (eq? lock-stat #f)) + (eq? (stat:type lock-stat) 'regular)) + (apply thunk '()) + (if (< i timeout) + (begin + (sleep 1) + (loop (+ 1 i))) + (throw 'timeout-error + "MySQL installation not locked in time!"))))))) + +(define (mysql-start config) + "Start mysqld if install lock file appears" + (program-file + "mysql-start" + (let ((mysql (mysql-configuration-mysql config)) + (my.cnf (mysql-configuration-file config))) + #~(let ((mysqld (string-append #$mysql "/bin/mysqld")) + (with-lock #$(mysql-with-install-lock))) + (with-lock (lambda () + (execl mysqld mysqld + (string-append "--defaults-file=" #$my.cnf)))))))) (define (mysql-shepherd-service config) (list (shepherd-service (provision '(mysql)) + (requirement '(mysql-install)) (documentation "Run the MySQL server.") - (start (let ((mysql (mysql-configuration-mysql config)) + (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" - #:log-file "/var/log/mysqld.log" - #:environment-variables #$extra-env))) + (list #$(mysql-start config)) + #:user "mysql" #:group "mysql" + #:log-file "/var/log/mysqld.log" + #:environment-variables #$extra-env))) (stop #~(make-kill-destructor))))) +(define (mysql-install config) + "Install MySQL system database and secure the installation." + (let ((mysql (mysql-configuration-mysql config)) + (my.cnf (mysql-configuration-file config)) + (datadir (mysql-configuration-datadir config)) + (extra-env (mysql-configuration-extra-environment config))) + (program-file + "mysql-install" + (with-imported-modules (source-module-closure + '((ice-9 popen) + (guix build utils))) + #~(begin + (use-modules (ice-9 popen) + (guix build utils)) + (let* ((mysqld (string-append #$mysql "/bin/mysqld")) + (user (getpwnam "mysql")) + (uid (passwd:uid user)) + (gid (passwd:gid user)) + (datadir #$datadir) + (rundir "/run/mysqld")) + (mkdir-p datadir) + (chown datadir uid gid) + (mkdir-p rundir) + (chown rundir uid gid) + ;; Initialize the database when it doesn't exist. + (when (not (file-exists? (string-append datadir "/mysql"))) + (if (string-prefix? "mysql-" (strip-store-file-name #$mysql)) + ;; For MySQL. + (system* mysqld + (string-append "--defaults-file=" #$my.cnf) + "--initialize" + "--user=mysql") + ;; For MariaDB. + ;; XXX: The 'mysql_install_db' script doesn't work directly + ;; due to missing 'mkdir' in PATH. + (let ((p (open-pipe* OPEN_WRITE mysqld + (string-append + "--defaults-file=" #$my.cnf) + "--bootstrap" + "--user=mysql"))) + ;; Create the system database, as does by 'mysql_install_db'. + (display "create database mysql;\n" p) + (display "use mysql;\n" p) + (for-each + (lambda (sql) + (call-with-input-file + (string-append #$mysql:lib "/share/mysql/" sql) + (lambda (in) (dump-port in p)))) + '("mysql_system_tables.sql" + "mysql_performance_tables.sql" + "mysql_system_tables_data.sql" + "fill_help_tables.sql")) + ;; Remove the anonymous user and disable root access from + ;; remote machines, as does by 'mysql_secure_installation'. + (display " +DELETE FROM user WHERE User=''; +DELETE FROM user WHERE User='root' AND + Host NOT IN ('localhost', '127.0.0.1', '::1'); +FLUSH PRIVILEGES; +" p) + (close-pipe p)))) + (call-with-output-file "/var/lib/mysql.lock" + (lambda (p) + (write #t p))))))))) + +(define (mysql-install-shepherd-service config) + (list (shepherd-service + (provision '(mysql-install)) + (requirement '(file-systems)) + (one-shot? #t) + (documentation "Install MySQL system database and secure installation.") + (start #~(make-forkexec-constructor + (list #$(mysql-install config)) + #:log-file "/var/log/mysqld-install.log"))))) + (define (mysql-upgrade-wrapper mysql socket-file) ;; The MySQL socket and PID file may appear before the server is ready to ;; accept connections. Ensure the socket is responsive before attempting @@ -631,7 +681,7 @@ FLUSH PRIVILEGES; "mysql-upgrade-wrapper" #~(begin (let ((mysql-upgrade #$(file-append mysql "/bin/mysql_upgrade")) - (timeout 10)) + (timeout 20)) (begin (let loop ((i 0)) (catch 'system-error @@ -663,11 +713,14 @@ FLUSH PRIVILEGES; (list #$(mysql-upgrade-wrapper mysql socket)) #:user "mysql" #:group "mysql")))))) + (define (mysql-shepherd-services config) - (if (mysql-configuration-auto-upgrade? config) - (append (mysql-shepherd-service config) + (let ((min-services (append (mysql-install-shepherd-service config) + (mysql-shepherd-service config)))) + (if (mysql-configuration-auto-upgrade? config) + (append min-services (mysql-upgrade-shepherd-service config)) - (mysql-shepherd-service config))) + min-services))) (define mysql-service-type (service-type @@ -675,8 +728,6 @@ FLUSH PRIVILEGES; (extensions (list (service-extension account-service-type (const %mysql-accounts)) - (service-extension activation-service-type - %mysql-activation) (service-extension shepherd-root-service-type mysql-shepherd-services))) (default-value (mysql-configuration)))) -- 2.32.0 ------------=_1668963422-6532-1--