services: mysql: Remove mysql-install-service in favor of wrapper.
* gnu/services/databases.scm (mysql-with-install-lock): Remove variable. (mysql-start): Rename to ... (mysqld-wrapper): ... this. Do the preliminary initialization steps and call out to MYSQL-INSTALL when necessary. (mysql-install): Only initialize table schemas. (mysql-install-shepherd-service): Remove. (mysql-service)[requirement]: Remove 'mysql-install. Add 'user-processes. [start]: Don't pass #:user and #:group. (mysql-shepherd-services): Remove MYSQL-INSTALL-SHEPHERD-SERVICE.master
parent
e4a74f38df
commit
3323ffa66d
|
@ -560,45 +560,45 @@ port=" (number->string port) "
|
||||||
" extra-content "
|
" extra-content "
|
||||||
"))))
|
"))))
|
||||||
|
|
||||||
(define (mysql-with-install-lock)
|
(define (mysqld-wrapper config)
|
||||||
"Return a loop function which evals thunk when the install is locked."
|
"Start mysqld, and initialize the system tables if necessary."
|
||||||
#~(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
|
(program-file
|
||||||
"mysql-start"
|
"mysqld-wrapper"
|
||||||
|
(with-imported-modules (source-module-closure
|
||||||
|
'((guix build utils)))
|
||||||
(let ((mysql (mysql-configuration-mysql config))
|
(let ((mysql (mysql-configuration-mysql config))
|
||||||
|
(datadir (mysql-configuration-datadir config))
|
||||||
(my.cnf (mysql-configuration-file config)))
|
(my.cnf (mysql-configuration-file config)))
|
||||||
#~(let ((mysqld (string-append #$mysql "/bin/mysqld"))
|
#~(begin
|
||||||
(with-lock #$(mysql-with-install-lock)))
|
(use-modules (guix build utils))
|
||||||
(with-lock (lambda ()
|
(let* ((mysqld (string-append #$mysql "/bin/mysqld"))
|
||||||
|
(user (getpwnam "mysql"))
|
||||||
|
(uid (passwd:uid user))
|
||||||
|
(gid (passwd:gid user))
|
||||||
|
(rundir "/run/mysqld"))
|
||||||
|
(mkdir-p #$datadir)
|
||||||
|
(chown #$datadir uid gid)
|
||||||
|
(mkdir-p rundir)
|
||||||
|
(chown rundir uid gid)
|
||||||
|
(unless (file-exists? (string-append #$datadir "/mysql"))
|
||||||
|
(let ((init (system* #$(mysql-install config))))
|
||||||
|
(unless (= 0 (status:exit-val init))
|
||||||
|
(throw 'system-error "MySQL initialization failed."))))
|
||||||
|
;; Drop privileges and start the server.
|
||||||
|
(setgid gid) (setuid uid)
|
||||||
(execl mysqld mysqld
|
(execl mysqld mysqld
|
||||||
(string-append "--defaults-file=" #$my.cnf))))))))
|
(string-append "--defaults-file=" #$my.cnf))))))))
|
||||||
|
|
||||||
(define (mysql-shepherd-service config)
|
(define (mysql-shepherd-service config)
|
||||||
(list (shepherd-service
|
(list (shepherd-service
|
||||||
(provision '(mysql))
|
(provision '(mysql))
|
||||||
(requirement '(mysql-install))
|
(requirement '(user-processes))
|
||||||
(documentation "Run the MySQL server.")
|
(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))
|
(extra-env (mysql-configuration-extra-environment config))
|
||||||
(my.cnf (mysql-configuration-file config)))
|
(my.cnf (mysql-configuration-file config)))
|
||||||
#~(make-forkexec-constructor
|
#~(make-forkexec-constructor
|
||||||
(list #$(mysql-start config))
|
(list #$(mysqld-wrapper config))
|
||||||
#:user "mysql" #:group "mysql"
|
|
||||||
#:log-file "/var/log/mysqld.log"
|
#:log-file "/var/log/mysqld.log"
|
||||||
#:environment-variables #$extra-env)))
|
#:environment-variables #$extra-env)))
|
||||||
(stop #~(make-kill-destructor)))))
|
(stop #~(make-kill-destructor)))))
|
||||||
|
@ -606,29 +606,15 @@ port=" (number->string port) "
|
||||||
(define (mysql-install config)
|
(define (mysql-install config)
|
||||||
"Install MySQL system database and secure the installation."
|
"Install MySQL system database and secure the installation."
|
||||||
(let ((mysql (mysql-configuration-mysql config))
|
(let ((mysql (mysql-configuration-mysql config))
|
||||||
(my.cnf (mysql-configuration-file config))
|
(my.cnf (mysql-configuration-file config)))
|
||||||
(datadir (mysql-configuration-datadir config))
|
|
||||||
(extra-env (mysql-configuration-extra-environment config)))
|
|
||||||
(program-file
|
(program-file
|
||||||
"mysql-install"
|
"mysql-install"
|
||||||
(with-imported-modules (source-module-closure
|
(with-imported-modules (source-module-closure
|
||||||
'((ice-9 popen)
|
'((guix build utils)))
|
||||||
(guix build utils)))
|
|
||||||
#~(begin
|
#~(begin
|
||||||
(use-modules (ice-9 popen)
|
(use-modules (ice-9 popen)
|
||||||
(guix build utils))
|
(guix build utils))
|
||||||
(let* ((mysqld (string-append #$mysql "/bin/mysqld"))
|
(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))
|
(if (string-prefix? "mysql-" (strip-store-file-name #$mysql))
|
||||||
;; For MySQL.
|
;; For MySQL.
|
||||||
(system* mysqld
|
(system* mysqld
|
||||||
|
@ -663,20 +649,7 @@ DELETE FROM user WHERE User='root' AND
|
||||||
Host NOT IN ('localhost', '127.0.0.1', '::1');
|
Host NOT IN ('localhost', '127.0.0.1', '::1');
|
||||||
FLUSH PRIVILEGES;
|
FLUSH PRIVILEGES;
|
||||||
" p)
|
" p)
|
||||||
(close-pipe 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 config)
|
(define (mysql-upgrade-wrapper config)
|
||||||
;; The MySQL socket and PID file may appear before the server is ready to
|
;; The MySQL socket and PID file may appear before the server is ready to
|
||||||
|
@ -721,12 +694,11 @@ FLUSH PRIVILEGES;
|
||||||
#:log-file "/var/log/mysql_upgrade.log")))))
|
#:log-file "/var/log/mysql_upgrade.log")))))
|
||||||
|
|
||||||
(define (mysql-shepherd-services config)
|
(define (mysql-shepherd-services config)
|
||||||
(let ((min-services (append (mysql-install-shepherd-service config)
|
(let ((mysql-services (mysql-shepherd-service config)))
|
||||||
(mysql-shepherd-service config))))
|
|
||||||
(if (mysql-configuration-auto-upgrade? config)
|
(if (mysql-configuration-auto-upgrade? config)
|
||||||
(append min-services
|
(append mysql-services
|
||||||
(mysql-upgrade-shepherd-service config))
|
(mysql-upgrade-shepherd-service config))
|
||||||
min-services)))
|
mysql-services)))
|
||||||
|
|
||||||
(define mysql-service-type
|
(define mysql-service-type
|
||||||
(service-type
|
(service-type
|
||||||
|
|
Reference in New Issue