Systemd

You are viewing an old version of this article. View the current version here.

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 in used, mysqld_safe is not used and no configuration of in the mysqld_safe section of configuration will be read or applied.

Systemd overview

systemd service files are included in the MariaDB-server package. The service definition is installed /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 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 currently can't be used yet (MDEV-9095);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, 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 to run the script galera_new_cluster.

Customisation

If there is some setting of systemd that to override or 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}

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

mysqld_safe optionsystemd optionComments
not applicableTimeoutStartSec={time}Set if the systemd reports failure to start because of timeout
open_filesLimitNOFILE={limit}
core_file_sizeLimitCORE={size}
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}

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.

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...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.