Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 466084 - dev-db/mysql-init-scripts: add systemd unit
Summary: dev-db/mysql-init-scripts: add systemd unit
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: Normal normal with 1 vote (vote)
Assignee: Gentoo Linux MySQL bugs team
URL: https://github.com/Sabayon/systemd-lo...
Whiteboard:
Keywords: NeedPatch
: 488896 498962 (view as bug list)
Depends on:
Blocks: install-systemd-unit systemd-love
  Show dependency tree
 
Reported: 2013-04-16 11:43 UTC by Fabio Erculiani (RETIRED)
Modified: 2015-06-21 10:09 UTC (History)
14 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabio Erculiani (RETIRED) gentoo-dev 2013-04-16 11:43:25 UTC
At URL, I committed a version of dev-db/{mysql,mariadb} featuring a systemd service unit in FILESDIR/ along with two support scripts.
Both unit and support scripts have been taken from Fedora [1] and slightly adapted to run on Gentoo.
I only tested mysql-5.5 and mariadb-5.5 and they work.


[1] http://pkgs.fedoraproject.org/cgit/community-mysql.git/tree/

Reproducible: Always
Comment 1 Brian Evans (RETIRED) gentoo-dev 2013-04-18 12:39:02 UTC
This should probably added to dev-db/mysql-init-scripts instead.
Much simpler to change.

Could even do things like IUSE="+openrc systemd" REQUIRED_USE="^^ ( openrc systemd )" there.
Comment 2 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-18 13:15:35 UTC
Yeah, probably mysql-init-scripts is the right place.

About the USE flag, that is wrong, we don't do that for systemd unit files nor for openrc init scripts. This has been discussed thousands of times on the mailing list already.
Comment 3 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-18 13:26:45 UTC
I just moved the systemd unit, the helper scripts and the tmpfiles.d conf to dev-db/mysql-init-scripts.
Comment 4 CBke -Left- bye 2013-04-19 20:24:18 UTC
I am using the scripts from https://github.com/Sabayon/systemd-love/tree/master/dev-db/mysql-init-scripts/files they seems to work fine, great job.

But to keep the functionality like openrc to run multiple slots:

make it /usr/lib64/systemd/system/mysqld@.service

and change ExecStart=/usr/bin/mysqld_safe to ExecStart=/usr/bin/mysqld_safe --defaults-file=/etc/mysql/%I.cnf

this way a symlink mysqld.my.service would use /etc/mysql/my.cnf and mysqld.my2.service would use /etc/mysql/my2.cnf
Comment 5 Fabio Erculiani (RETIRED) gentoo-dev 2013-04-21 09:41:02 UTC
commit 4c4233646731f84439134f48ae79144e96c0d991
Author: Fabio Erculiani <lxnay@sabayon.org>
Date:   Sun Apr 21 11:38:27 2013 +0100

    [dev-db/mysql-init-scripts] allow slotted mysqld instances

Done but I used /my%I.cnf so that "systemctl enable mysqld" keeps working.
Comment 6 Pacho Ramos gentoo-dev 2013-07-05 16:50:19 UTC
Changes can be takedn from systemd-love overlay. I will commit in a week if nobody disagrees. Thanks
Comment 7 Alexander Tsoy 2013-07-11 18:34:15 UTC
(In reply to Fabio Erculiani from comment #5)
> commit 4c4233646731f84439134f48ae79144e96c0d991
> Author: Fabio Erculiani <lxnay@sabayon.org>
> Date:   Sun Apr 21 11:38:27 2013 +0100
> 
>     [dev-db/mysql-init-scripts] allow slotted mysqld instances
> 
> Done but I used /my%I.cnf so that "systemctl enable mysqld" keeps working.

$ sudo systemctl enable mysqld
Failed to issue method call: No such file or directory
$ sudo systemctl enable mysqld@.service
ln -s '/usr/lib64/systemd/system/mysqld@.service' '/etc/systemd/system/multi-user.target.wants/mysqld@.service'
Comment 8 Alexander Tsoy 2013-07-11 18:37:15 UTC
(In reply to Alexander Tsoy from comment #7)

And then:

$ sudo systemctl start mysqld@.service
Failed to issue method call: Unit name mysqld@.service is not valid.

So I think ebuild shoud install two units: mysqld@.service and mysqld.service
Comment 9 Pacho Ramos gentoo-dev 2013-08-20 09:11:55 UTC
(In reply to Alexander Tsoy from comment #8)
> (In reply to Alexander Tsoy from comment #7)
> 
> And then:
> 
> $ sudo systemctl start mysqld@.service
> Failed to issue method call: Unit name mysqld@.service is not valid.
> 
> So I think ebuild shoud install two units: mysqld@.service and mysqld.service

Probably, if you could provide a diff would be really appreciated :)
Comment 10 Alexander Tsoy 2013-08-26 13:07:50 UTC
(In reply to Pacho Ramos from comment #9)

Just apply this patch reversed and you will get the original mysqld.service :)

https://github.com/Sabayon/systemd-love/commit/4c4233646731f84439134f48ae79144e96c0d991#diff-1

Also mysqld-prepare-db-dir script is not compatible with the mysqld@.service.
Comment 11 Alexander Tsoy 2013-08-26 13:38:31 UTC
(In reply to Alexander Tsoy from comment #10)
> Also mysqld-prepare-db-dir script is not compatible with the mysqld@.service.

It always initialize db in /var/lib/mysql.
Comment 12 Pacho Ramos gentoo-dev 2013-08-27 08:34:27 UTC
(In reply to Alexander Tsoy from comment #10)
> Also mysqld-prepare-db-dir script is not compatible with the mysqld@.service.

I guess more work will be needed still. Also, reverting the systemd-love commit will lose slot support, is that wanted?
Comment 13 Alexander Tsoy 2013-08-27 08:59:55 UTC
(In reply to Pacho Ramos from comment #12)
> (In reply to Alexander Tsoy from comment #10)
> > Also mysqld-prepare-db-dir script is not compatible with the mysqld@.service.
> 
> I guess more work will be needed still.

This script should not be too smart - initializing of the DB is not its work. For example /var/lib/mysql can be a mounting point that is not mounted for some reason. In that case the unit must fail. So I would prefer that "mysqld-prepare-db-dir" is based on our init script (then it should be named "mysqld-check-db-dir").

Are there any objections?

> Also, reverting the systemd-love commit will lose slot support, is that wanted?

I just pointed you to the diff between original mysqld.service and template unit mysqld@.service. I didn't mean that you should delete the latter. :)
Comment 14 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2013-08-27 09:20:06 UTC
(In reply to Alexander Tsoy from comment #13)
> (In reply to Pacho Ramos from comment #12)
> > (In reply to Alexander Tsoy from comment #10)
> > > Also mysqld-prepare-db-dir script is not compatible with the mysqld@.service.
> > 
> > I guess more work will be needed still.
> 
> This script should not be too smart - initializing of the DB is not its
> work. For example /var/lib/mysql can be a mounting point that is not mounted
> for some reason. In that case the unit must fail. So I would prefer that
> "mysqld-prepare-db-dir" is based on our init script (then it should be named
> "mysqld-check-db-dir").
> 
> Are there any objections?

And what is the benefit of doing that check? Doesn't mysqld fail on its own when there is no config or database?
Comment 15 Alexander Tsoy 2013-08-27 09:52:53 UTC
(In reply to Michał Górny from comment #14)
> And what is the benefit of doing that check? Doesn't mysqld fail on its own
> when there is no config or database?

With empty datadir mysqld fails to start, but it creates some files in it =/

$ sudo ls -a /var/lib/mysql
.  ..  aria_log.00000001  aria_log_control  ibdata1  ib_logfile0  ib_logfile1

Also this script is for convenience. If you start mysqld service without any checks and with an empty datadir, then you get these uninformative messages in the journal:

Aug 27 13:31:58 HOSTNAME systemd[1]: Starting MySQL database server...
Aug 27 13:31:59 HOSTNAME mysqld_safe[26951]: 130827 13:31:59 mysqld_safe Logging to '/var/log/mysql/mysqld.err'.
Aug 27 13:31:59 HOSTNAME mysqld_safe[26951]: 130827 13:31:59 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Aug 27 13:32:01 HOSTNAME mysqld_safe[26951]: 130827 13:32:01 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Aug 27 13:32:02 HOSTNAME systemd[1]: mysqld.service: control process exited, code=exited status=1
Aug 27 13:32:02 HOSTNAME systemd[1]: Failed to start MySQL database server.
Aug 27 13:32:02 HOSTNAME systemd[1]: Unit mysqld.service entered failed state.
Comment 16 Fabio Erculiani (RETIRED) gentoo-dev 2013-08-27 09:55:17 UTC
Why is there so much talk on this bug? Just provide a mysqld.service and we're fine. At the time, when I tested both scenarios, everything was working fine for me.

Moreover, the setup code in the init script is overkill. The Fedora way is the right one wrt supporting multiple init systems.

So, my advice is: just take mysqld@.service and write mysqld.service and close the bug.
Comment 17 Pacho Ramos gentoo-dev 2013-09-03 18:49:55 UTC
+*mysql-init-scripts-2.0_pre1-r4 (03 Sep 2013)
+
+  03 Sep 2013; Pacho Ramos <pacho@gentoo.org> +files/mysql.conf,
+  +files/mysqld-prepare-db-dir, +files/mysqld-wait-ready, +files/mysqld.service,
+  +files/mysqld_at.service, +mysql-init-scripts-2.0_pre1-r4.ebuild:
+  Add systemd support (#466084)
+
Comment 18 Pacho Ramos gentoo-dev 2013-10-21 17:13:02 UTC
*** Bug 488896 has been marked as a duplicate of this bug. ***
Comment 19 Alex Xu (Hello71) 2014-01-23 02:22:21 UTC
*** Bug 498962 has been marked as a duplicate of this bug. ***