systemd is an init replacement that MariaDB uses on releases since 10.1.8. Distribution packages before this version may use a different configuration so consult their documentation if required.

systemd services are packaged on RPM and Debian based Linux distributions. When systemd is used, mysqld_safe is not used and settings in the mysqld_safe section of configuration files will not be read or applied.

systemd overview

systemd service files are included in the MariaDB-server package. The service definition is installed in /usr/lib/systemd/system/mariadb.service. The service name is mariadb.service; however aliases to mysql.service and mysqld.service are included for convenience.

Unlike previous init scripts, the mysqld process is executed directly from the init script running as the mysql user. This places a couple of limitations on situations that were previously possible:

  • open-files-limit cannot be raised beyond the operating system limit (usually 1K) and hence the systemd configuration for mariadb has LimitNOFILE set to 16K by default;
  • memlock can be used from version 10.1.10; and
  • The start timeout from init scripts was quite large and special configuration may be required if there is a slow startup time (MDEV-9202).

Galera

Previously bootstrapping Galera and creating the current server as the primary data after a cluster wide shutdown required service mysqld bootstrap. In systemd this isn't possible and the equivalent is to run the script galera_new_cluster.

Customization

If there are some systemd settings to override or to set, create a file /etc/systemd/system/mariadb.service.d/XXXX.conf file where XXXX is something meaningful to you and place the configuration option(s) in an appropriate section, usually [Service]. If a systemd option is a list you may need to set this to empty before you set the replacement values, e.g.:

[Service]

ExecStart=
ExecStart=/usr/bin/numactl --interleave=all  /usr/sbin/mysqld ${MYSQLD_OPTS} ${_WSREP_NEW_CLUSTER} ${_WSREP_START_POSITION}

After any configuration change systemctl daemon-reload will be required to pick up the changes.

A mapping of common mysqld_safe options to systemd options is provided below.

mysqld_safe optionsystemd optionComments
no optionProtectHome=falseIf any MariaDB files are in /home/
no optionPrivateDevices=falseIf any MariaDB storage references raw block devices
no optionProtectSystem=If any MariaDB write any files to anywhere under /boot, /usr or /etc
no optionTimeoutStartSec={time}Set if the systemd reports failure to start because of timeout. 0 disables any timeout
no option (ref MDEV-9264)OOMScoreAdjust={priority}e.g. -600 to lower priority of OOM killer for mysqld
open_filesLimitNOFILE={limit}
core_file_sizeLimitCORE={size}
LimitMEMLOCK={size} or unlimitedWhen large-pages or memlock is used
niceNice={nice value}
syslogStandardOutput=syslog
StandardError=syslog
SyslogFacility=daemon
SyslogLevel=err
syslog-tagSyslogIdentifier
flush-cachesExecStartPre=/usr/bin/sync
ExecStartPre=/usr/sbin/sysctl -q -w vm.drop_caches=3
numa-interleaveExecStart=/usr/bin/numactl --interleave=all /usr/sbin/mysqld ${MYSQLD_OPTS} ${_WSREP_NEW_CLUSTER} ${_WSREP_START_POSITION}

Note: systemd.service contains the official meanings for these systemd settings.

There are other options and the mariadb-service-convert script will attempt to convert these as accurately as possible.

In addition to the set of options previously provided by mysqld_safe, systemd.service has considerably more options.

Logging

systemd has its own logging system called the systemd journal. Logs that might have been found before in the default error log file or in syslog may instead be logged by systemd.

To read all the MariaDB server logs, use the following command: journalctl -u mariadb

Multiple instances

/usr/lib/systemd/system/mariadb@.service is installed on some systems. This is a multiple instance if you run multiple instances of MariaDB on the same hardware.

For systemd, systemctl start mariadb@testserver, will start a mariadb instance based on the config file /etc/my.cnf.d/mytestserver.cnf. The instance name, testserver, is substituted in /etc/my.cnf.d/my%I.cnf where the %I is. Any instance name can be chosen and the required configuration is to create its configuration file and database (see mysqld_install_db).

To start an instance on bootup, systemctl enable mariadb@testserver.

Conversion

mariadb-service-convert is a script included in the distribution. It is used by the package manager to read any explicit settings in the mysqld_safe section on the configuration file and its output can be directed to /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf to keep the configuration the same. Implicitly high defaults of open-file-limit may be missed by the conversion script and require explicit configuration.

Comments

Comments loading...