[MDEV-427] Provide a systemd script for MariaDB Created: 2012-08-02  Updated: 2023-05-09  Resolved: 2015-10-15

Status: Closed
Project: MariaDB Server
Component/s: Packaging
Fix Version/s: 10.1.8

Type: Task Priority: Critical
Reporter: Colin Charles Assignee: Sergey Vojtovich
Resolution: Fixed Votes: 11
Labels: packaging, systemd

Issue Links:
Blocks
blocks MDEV-4606 cmake build to be able to choose sysv... Closed
blocks MDEV-5536 Support systemd socket activation Closed
blocks MDEV-7752 There is no bootstrap command option ... Closed
PartOf
includes MDEV-7694 MariaDB - mysqld cannot start when re... Closed
Relates
relates to MDEV-5713 RFE: Add support for systemd notify f... Closed
relates to MDEV-6347 Build RHEL7 packages Closed
Sprint: 10.1.7-1, 10.1.7-2, 10.1.8-1, 10.1.8-3, 10.1.8-4

 Description   

MySQL doesn't provide a systemd (http://www.freedesktop.org/wiki/Software/systemd/) script and thus distributions that are shipping systemd have to provide their own. Not many like this. So should we provide one inside the MariaDB package to be better for distributions than MySQL?

Some references:



 Comments   
Comment by AL13N [ 2012-08-02 ]

see also http://svnweb.mageia.org/packages/cauldron/mariadb/current/SOURCES/mysqld.service?view=log for mysqld.service script from mageia

Comment by Otto Kekäläinen [ 2014-08-27 ]

More links do downstream versions:

OpenSUSE: https://build.opensuse.org/package/view_file/server:database/mariadb/mysql.service?expand=1

Fedora (uses two service files):
http://pkgs.fedoraproject.org/cgit/mariadb.git/tree/mysql.service.in
http://pkgs.fedoraproject.org/cgit/mariadb.git/tree/mysql-compat.service.in

Arch: https://projects.archlinux.org/svntogit/packages.git/tree/trunk/mariadb.service?h=packages/mariadb

These are all different. They all even use different service names: mysql, mysqld, mariadb and mysql+mysql-compat.

I'll do one for Debian once I figure out what the optimal service file should look like.

Comment by David Strauss [ 2014-08-28 ]

It's possible to use one main service name and then configure an alias (in the units) as appropriate for each distro.

Comment by erkan yanar [ 2014-08-28 ]

We should not waste time with broken examples.
i.e. the SUSE stuff:

 
[Service]
Type=forking
ExecStart=/usr/lib/mysql/rcmysql start
ExecStop=/usr/lib/mysql/rcmysql stop
 

This is broken. You use systemd to start the binary.
systemd takes care
To stop a SIGTERM is sufficient
Using mysqld_safe is also forbidden.
systemd takes care of restarting a service.

Comment by erkan yanar [ 2014-08-28 ]

I had an look at the mariadb package from fedora20 and changed it

[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target
 
[Service]
# It is all default just for documentation
Type=simple
User=mysql
Group=mysql
 
# Removed that on. Should be done in the package
#ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
 
# Changed from mysqld_safe to mysql
ExecStart=/usr/libexec/mysqld
 
# Makes no real sense to wait for the mainpid we already control it
#ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID
 
# Just defining the was how to kill mysqld.
KillMode=process
KillSignal=SIGTERM
# Thats me I don't want to see an automated SIGKILL ever
SendSIGKILL=no
 
# I hate timeouts. Most likely sysadmins use them and revert my SendSIGKILL
#TimeoutSec=300
 
# We restart mysqld if there is a failure (5s delay)
Restart=on-failure
RestartSec=5s
 
PrivateTmp=true
 
[Install]
# So we can use mysql and mariad as service
Alias=mysql.service
WantedBy=multi-user.target

Comment by David Strauss [ 2014-08-28 ]

"Makes no real sense to wait for the mainpid we already control it"

I disagree. With a Type=simple service, systemd considers the service fully running as soon as systemd starts running ExecStart. This is problematic if other services depend on MariaDB and need to run after its fully online.

Comment by AL13N [ 2014-08-28 ]

for mageia, i would like to change this to not use mysqld_safe either...

anyway, i'm open to suggestions...

Comment by Christian McHugh [ 2014-11-24 ]

In our environment we have about 1000 mariadb/mysql databases. It takes a few minutes for everything to fully come up and be ready to serve connections. The redhat service file includes a ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID bit where that script loops with "/usr/bin/mysqladmin --no-defaults --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping" until it can successfully connect (not successfully login, just connect). Something like that will probably be required to ensure the service is really up.

Comment by Otto Kekäläinen [ 2014-11-25 ]

mchugh19 The old init scripts have a section that waits for service to come up (and also to stop at shutdown/restart) which uses the mysqld_status command. See http://anonscm.debian.org/cgit/pkg-mysql/mariadb-10.0.git/tree/debian/mariadb-server-10.0.mysql.init

Others: http://0pointer.net/public/systemd-nluug-2014.pdf presents the systemd security features, which are encouraged (at least in Debian) to be used.

Comment by erkan yanar [ 2014-12-05 ]

Hmm,
Both do the same in the end.
Imho it is embarrassing to have still no systemd integration at all.
The whole world takes MariaDB into there distribution. systemd is going to be the PID 1
and MariaDB is not able to get this done.

Comment by Daniel Black [ 2015-01-07 ]

Avoided all deficiencies of type=

{simple|forking}

by using Type=Notify in MDEV-5536. Thanks for the base service file erkules. I've also seen a possibility of doing database install like sshd-keygen.service (https://bugzilla.redhat.com/show_bug.cgi?id=1066615#c7).

Comment by erkan yanar [ 2015-02-26 ]

Oh notify is indeed a very nice opportunity. Making it not that "simple" anymore

Making things more complex:
I would like to agree on how/when to initialise datadir.
Like Debian/Ubuntu on installation or on startup.

Comment by erkan yanar [ 2015-02-26 ]

Btw: As with 10.1 and integrated Galera we need to take care of --wsrep-recover's job in mysqld_safe also

Comment by Daniel Black [ 2015-03-11 ]

initialisations support-files/mariadb-systemd-start make it as late as possible, hopefully my.cnf files are populated by the time a user starts a service.

wsrep-recover -looks like its something that should be moved into mysqld rather than running mysqld, extracting output and running mysqld again.

https://github.com/MariaDB/server/pull/26 included systemd script

Comment by Nils Meyer [ 2015-07-16 ]

This effectively prevents me from using MariaDB Galera in Debian Jessie since it's not possible to bootstrap the cluster without launching mysqld manually with the --wsrep-new-cluster, which will subsequently prevent managing the service through systemd.

Comment by Daniel Black [ 2015-07-17 ]

nils.meyer yeh, perhaps having a type=oneshot or different service for that specific purpose that isn't part of the default. I'll see what I can make up. Quite a few things to consider for that however.

I'll add them on top of the current pull request.

https://github.com/MariaDB/server/pull/83

Comment by Daniel Black [ 2015-07-24 ]

nils.meyer - MDEV-7752 - focuses on Centos7 however something might be applicable for you.

Comment by Julien Pivotto [ 2015-07-28 ]

would it be possible to ship that for 10.0 as well?

Comment by Sergei Golubchik [ 2015-07-28 ]

We'd love to. But as it turned out, users don't like when we add new dependencies to our packages in a GA branch (yes, we've tried). And in these patches MariaDB is linked with libsystemd-daemon.so, so we'll have to add it as a dependency. We cannot do that. I see few options for 10.0:

  • add the patch nevertheless, but build our packages without systemd. Users would need to compile MariaDB to get systemd support.
  • bundle libsystemd-daemon sources with 10.0
  • only implement a minimal systemd support in 10.0 that doesn't require changes in the server

What do you think we should do?

Either way, I think we'll add systemd support in 10.1 first and then, possibly, backport parts of it to 10.0

Comment by Guillaume Lefranc [ 2015-07-28 ]

Sergei,

I would suggest the third choice, aka minimal systemd support. This is the less intrusive, and to be honest, most people just need minimal support.
Let's keep the systemd socket activation for 10.1 as it introduces major changes.

Regards,
Guillaume

Comment by Otto Kekäläinen [ 2015-07-28 ]

I agree with serg about being conservative in GA branches. Add well documented systemd scripts to 10.1 and downstream packagers can then choose themselves if they want to take the risk of backporting it somewhere, e.g. to new OS/Linux distro releases.

Generated at Thu Feb 08 06:28:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.