Commit 20c2ae39 authored by Daniel Black's avatar Daniel Black Committed by Sergey Vojtovich

MDEV-427/MDEV-5713 Add systemd script with notify functionality

parent 92271c78
......@@ -197,6 +197,7 @@ support-files/config.huge.ini
support-files/config.medium.ini
support-files/config.small.ini
support-files/mariadb.pc
support-files/mariadb@.service
support-files/my-huge.cnf
support-files/my-innodb-heavy-4G.cnf
support-files/my-large.cnf
......
......@@ -151,6 +151,7 @@ INCLUDE(pcre)
INCLUDE(ctest)
INCLUDE(plugin)
INCLUDE(install_macros)
INCLUDE(systemd)
INCLUDE(mysql_add_executable)
# Handle options
......@@ -328,6 +329,8 @@ CHECK_JEMALLOC()
CHECK_PCRE()
CHECK_SYSTEMD()
IF(CMAKE_CROSSCOMPILING)
SET(IMPORT_EXECUTABLES "IMPORTFILE-NOTFOUND" CACHE FILEPATH "Path to import_executables.cmake from a native build")
INCLUDE(${IMPORT_EXECUTABLES})
......
# Copyright (c) 2015, Daniel Black. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
INCLUDE(FindPkgConfig)
# http://www.cmake.org/cmake/help/v3.0/module/FindPkgConfig.html
MACRO(CHECK_SYSTEMD)
IF(UNIX)
SET(WITH_SYSTEMD "auto" CACHE STRING "Compile with systemd socket activation and notification")
IF(WITH_SYSTEMD STREQUAL "yes" OR WITH_SYSTEMD STREQUAL "auto")
IF(PKG_CONFIG_FOUND)
IF(WITH_SYSTEMD STREQUAL "yes")
pkg_check_modules(LIBSYSTEMD REQUIRED libsystemd)
ELSE()
pkg_check_modules(LIBSYSTEMD libsystemd)
ENDIF()
IF(HAVE_DLOPEN)
SET(LIBSYSTEMD ${LIBSYSTEMD_LIBRARIES})
#SET(CMAKE_REQUIRED_FLAGS ${LIBSYSTEMD_CFLAGS})
SET(MYSQLD_LINK_FLAGS "${MYSQLD_LINK_FLAGS} ${LIBSYSTEMD_LDFLAGS}")
ELSE()
SET(LIBSYSTEMD ${LIBSYSTEMD_STATIC_LIBRARIES})
#SET(CMAKE_REQUIRED_FLAGS ${LIBSYSTEMD_STATIC_CFLAGS})
SET(MYSQLD_LINK_FLAGS "${MYSQLD_LINK_FLAGS} ${LIBSYSTEMD_STATIC_LDFLAGS}")
ENDIF()
ELSE()
SET(LIBSYSTEMD systemd)
ENDIF()
SET(CMAKE_REQUIRED_LIBRARIES ${LIBSYSTEMD})
CHECK_C_SOURCE_COMPILES(
"
#include <systemd/sd-daemon.h>
int main()
{
sd_listen_fds(0);
}"
HAVE_SYSTEMD)
CHECK_INCLUDE_FILES(systemd/sd-daemon.h HAVE_SYSTEMD_SD_DAEMON_H)
CHECK_FUNCTION_EXISTS(sd_listen_fds HAVE_SYSTEMD_SD_LISTEN_FDS)
CHECK_FUNCTION_EXISTS(sd_notify HAVE_SYSTEMD_SD_NOTIFY)
CHECK_FUNCTION_EXISTS(sd_notifyf HAVE_SYSTEMD_SD_NOTIFYF)
IF(HAVE_SYSTEMD AND HAVE_SYSTEMD_SD_DAEMON_H AND HAVE_SYSTEMD_SD_LISTEN_FDS
AND HAVE_SYSTEMD_SD_NOTIFY AND HAVE_SYSTEMD_SD_NOTIFYF)
ADD_DEFINITIONS(-DHAVE_SYSTEMD)
# should be from pkg-config --variable=systemdsystemconfdir systemd
# Missing CMake macro: http://public.kitware.com/Bug/view.php?id=15634
SET(SYSTEMD_SYSTEM_CONFDIR /etc/systemd/system)
# should be from pkg-config --variable=systemdsystemunitdir systemd
SET(SYSTEMD_SYSTEM_UNITDIR /usr/lib/systemd/system/)
MESSAGE(STATUS "Systemd features enabled")
ELSE()
UNSET(LIBSYSTEMD)
UNSET(HAVE_SYSTEMD_SD_DAEMON_H)
UNSET(HAVE_SYSTEMD_SD_LISTEN_FDS)
UNSET(HAVE_SYSTEMD_SD_NOTIFY)
UNSET(HAVE_SYSTEMD_SD_NOTIFYF)
MESSAGE(STATUS "Systemd features not enabled")
IF(WITH_SYSTEMD STREQUAL "yes")
MESSAGE(FATAL_ERROR "Requested WITH_SYSTEMD=YES however no dependencies installed/found")
ENDIF()
ENDIF()
ENDIF()
ENDIF()
ENDMACRO()
......@@ -120,6 +120,7 @@
#cmakedefine HAVE_LIBCRYPT 1
#cmakedefine HAVE_LIBMTMALLOC 1
#cmakedefine HAVE_LIBWRAP 1
#cmakedefine HAVE_SYSTEMD 1
/* Does "struct timespec" have a "sec" and "nsec" field? */
#cmakedefine HAVE_TIMESPEC_TS_SEC 1
......
......@@ -23,6 +23,7 @@ Build-Depends: bison,
zlib1g-dev (>= 1:1.1.3-5~),
${MAYBE_LIBCRACK}
libjemalloc-dev (>= 3.0.0~) [linux-any]
libsystemd-daemon-dev | libsystemd-dev, dh-systemd
Standards-Version: 3.8.2
Homepage: http://mariadb.org/
Vcs-Git: https://github.com/MariaDB/server.git
......
......@@ -55,6 +55,7 @@ usr/bin/wsrep_sst_mysqldump
usr/bin/wsrep_sst_rsync
usr/bin/wsrep_sst_xtrabackup
usr/bin/wsrep_sst_xtrabackup-v2
usr/bin/mariadb-system-convert
usr/share/doc/mariadb-server-10.1/mysqld.sym.gz
usr/share/doc/mariadb-server-10.1/INFO_SRC
usr/share/doc/mariadb-server-10.1/INFO_BIN
......
......@@ -276,6 +276,12 @@ if [ "$1" = "configure" ]; then
db_go
fi
# copy out any mysqld_safe settings
systemd_conf=/etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
if [ -x /usr/bin/mariadb-service-convert -a ! -f "${systemd_conf}" ]; then
mkdir -p /etc/systemd/system/mariadb.service.d
/usr/bin/mariadb-service-convert > "${systemd_conf}"
fi
fi
db_stop # in case invoke failes
......
......@@ -180,6 +180,12 @@ install: build
install -m 0644 $(builddir)/Docs/INFO_SRC $(TMP)/usr/share/doc/mariadb-server-10.1/INFO_SRC
install -m 0644 $(builddir)/Docs/INFO_BIN $(TMP)/usr/share/doc/mariadb-server-10.1/INFO_BIN
# systemd helpers
install -m 0755 scripts/mariadb-service-convert $(TMP)/usr/bin/
install -d $(TMP)/etc/systemd/system/mariadb@bootstrap.service.d/
install -m 0644 $(BUILDDIR)/support-files/mariadb-bootstrap.conf \
$(TMP)/etc/systemd/system/mariadb@bootstrap.service.d/wsrep-new-cluster.conf
# mariadb-test
mv $(TMP)/usr/mysql-test $(TMP)/usr/share/mysql
......@@ -215,7 +221,10 @@ binary-indep: build install
dh_installexamples -i
dh_installmenu -i
dh_installlogrotate -i
dh_systemd_enable -i support-files/mariadb.service
dh_systemd_enable --no-enable support-files/mariadb@.service
dh_installinit -i
dh_systemd_start -i --restart-after-upgrade mariadb.service
dh_installcron -i
dh_installman -i
dh_installinfo -i
......
#ifndef MY_SYSTEMD_INCLUDED
#define MY_SYSTEMD_INCLUDED
#if defined(HAVE_SYSTEMD) && !defined(EMBEDDED_LIBRARY)
#include <systemd/sd-daemon.h>
#else
#define sd_notify(X, Y)
#define sd_notifyf(E, F, ...)
#endif
#endif /* MY_SYSTEMD_INCLUDED */
......@@ -300,6 +300,7 @@ ELSE()
mysqld_multi
mysqld_safe
${WSREP_BINARIES}
mariadb-service-convert
)
FOREACH(file ${BIN_SCRIPTS})
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh)
......
#!/bin/bash
# Copyright (c) 2015, Daniel Black. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# PURPOSE:
#
# Used to generate a mariadb.service file based on the curent mysql/maridb settings
#
# This is to assist distro maintainers in migrating to systemd service definations from
# a user mysqld_safe settings in the my.cnf files.
#
# Redirect output to user directory like /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
tz_old=$TZ
get_params()
{
# does a return so needs to be wrapped in a function
# . /usr/bin/mysqld_safe --simulate
. scripts/mysqld_safe --simulate
}
get_params
echo "# converted using $0"
echo "#"
echo
echo '[Service]'
echo
if [[ ( "$user" != "root" && "$user" != "mysql" ) || "${SET_USER}" == 1 ]]; then
echo User=$user
fi
[ -n "${open_files}" ] && echo LimitNOFILE=$open_files
[ -n "${core_file_size}" ] && echo LimitCore=$core_file_size
[[ "${niceness}" -gt 0 ]] && echo Nice=$niceness
[ "${TZ}" != "${tz_old}" ] && echo Environment=\"TZ=${TZ}\"
if [ -n "$mysqld_ld_preload" ]; then
new_text="$mysqld_ld_preload"
[ -n "$LD_PRELOAD" ] && new_text="$new_text $LD_PRELOAD"
echo Environment=\"LD_PRELOAD=`shell_quote_string "$new_text"`\"
fi
if [ -n "$mysqld_ld_library_path" ]; then
new_text="$mysqld_ld_library_path"
[ -n "$LD_LIBRARY_PATH" ] && new_text="$new_text:$LD_LIBRARY_PATH"
echo Environment=\"LD_LIBRARY_PATH=`shell_quote_string "$new_text"`\"
fi
if [[ $want_syslog -eq 1 ]]; then
echo StandardError=syslog
echo SyslogFacility=daemon
echo SyslogLevel=error
echo SyslogLevelPrefix=${syslog_tag_mysqld}
fi
if [[ "${flush_caches}" -gt 0 ]]; then
echo ExecStartPre=sync
echo ExecStartPre=sysctl -q -w vm.drop_caches=3
fi
if [[ "${numa_interleave}" -gt 0 ]]; then
echo
echo ExecStart=numactl --interleave=all ${cmd} '${OPTIONS}'
echo
fi
[ -n "${CRASH_SCRIPT}" ] && echo FailureAction=${CRASH_SCRIPT}
......@@ -21,6 +21,7 @@ mysqld_ld_library_path=
flush_caches=0
numa_interleave=0
wsrep_on=0
simulate=0
# Initial logging status: error log is not open, and not using syslog
logging=init
......@@ -81,6 +82,7 @@ Usage: $0 [OPTIONS]
--malloc-lib=LIB Preload shared library LIB if available
--mysqld=FILE Use the specified file as mysqld
--mysqld-version=VERSION Use "mysqld-VERSION" as mysqld
--simulate Simulate the start to detect errors but don't start
--nice=NICE Set the scheduling priority of mysqld
--no-auto-restart Exit after starting mysqld
--nowatch Exit after starting mysqld
......@@ -131,6 +133,7 @@ my_which ()
}
log_generic () {
[ $simulate -eq 1 ] && return
priority="$1"
shift
......@@ -318,6 +321,7 @@ parse_arguments() {
MYSQLD="mysqld"
fi
;;
--simulate) simulate=1 ;;
--nice=*) niceness="$val" ;;
--nowatch|--no[-_]watch|--no[-_]auto[-_]restart) nowatch=1 ;;
--open[-_]files[-_]limit=*) open_files="$val" ;;
......@@ -862,7 +866,7 @@ fi
#
# If there exists an old pid file, check if the daemon is already running
# Note: The switches to 'ps' may depend on your operating system
if test -f "$pid_file"
if test -f "$pid_file" && [ $simulate -eq 0 ]
then
PID=`cat "$pid_file"`
if @CHECK_PID@
......@@ -937,7 +941,9 @@ fi
# ulimit -n 256 > /dev/null 2>&1 # Fix for BSD and FreeBSD systems
#fi
cmd="`mysqld_ld_preload_text`$NOHUP_NICENESS"
[ $simulate -eq 0 ] && cmd=''
#
# Set mysqld's memory interleave policy.
......@@ -957,7 +963,7 @@ then
fi
# Launch mysqld with numactl.
cmd="$cmd numactl --interleave=all"
[ $simulate -eq 0 ] && cmd="$cmd numactl --interleave=all"
elif test $numa_interleave -eq 1
then
log_error "--numa-interleave is not supported on this platform"
......@@ -971,6 +977,7 @@ do
done
cmd="$cmd $args"
# Avoid 'nohup: ignoring input' warning
[ $simulate -eq 0 ] && cmd='true'
test -n "$NOHUP_NICENESS" && cmd="$cmd < /dev/null"
log_notice "Starting $MYSQLD daemon with databases from $DATADIR"
......
......@@ -168,7 +168,8 @@ TARGET_LINK_LIBRARIES(sql ${MYSQLD_STATIC_PLUGIN_LIBS}
mysys mysys_ssl dbug strings vio pcre ${LIBJEMALLOC}
${LIBWRAP} ${LIBCRYPT} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT}
${WSREP_LIB}
${SSL_LIBRARIES})
${SSL_LIBRARIES}
${LIBSYSTEMD})
IF(WIN32)
SET(MYSQLD_SOURCE main.cc nt_servc.cc nt_servc.h message.rc)
......
......@@ -110,6 +110,8 @@
#include <poll.h>
#endif
#include <my_systemd.h>
#define mysqld_charset &my_charset_latin1
/* We have HAVE_valgrind below as this speeds up the shutdown of MySQL */
......@@ -1891,6 +1893,8 @@ static void __cdecl kill_server(int sig_ptr)
else
sql_print_error(ER_DEFAULT(ER_GOT_SIGNAL),my_progname,sig); /* purecov: inspected */
sd_notify(0, "STOPPING=1");
#ifdef HAVE_SMEM
/*
Send event to smem_event_connect_request for aborting
......@@ -6543,6 +6547,11 @@ void handle_connections_sockets()
socket_flags=fcntl(mysql_socket_getfd(unix_sock), F_GETFL, 0);
#endif
#ifdef HAVE_SYSTEMD
sd_notify(0, "READY=1\n"
"STATUS=Taking your SQL requests now...");
#endif
DBUG_PRINT("general",("Waiting for connections."));
MAYBE_BROKEN_SYSCALL;
while (!abort_loop)
......@@ -6757,6 +6766,7 @@ void handle_connections_sockets()
create_new_thread(thd);
set_current_thd(0);
}
sd_notify(0, "STOPPING=1");
DBUG_VOID_RETURN;
}
......
......@@ -48,6 +48,8 @@ this program; if not, write to the Free Software Foundation, Inc.,
#include <io.h>
#endif
#include <my_systemd.h>
/** @file ha_innodb.cc */
/* Include necessary InnoDB headers */
......@@ -20112,9 +20114,11 @@ ib_logf(
break;
case IB_LOG_LEVEL_ERROR:
sql_print_error("InnoDB: %s", str);
sd_notifyf(0, "STATUS=InnoDB: Error: %s", str);
break;
case IB_LOG_LEVEL_FATAL:
sql_print_error("InnoDB: %s", str);
sd_notifyf(0, "STATUS=InnoDB: Fatal: %s", str);
break;
}
......
......@@ -30,6 +30,8 @@ Created 9/20/1997 Heikki Tuuri
#include <stdio.h> // Solaris/x86 header file bug
#include <vector>
#include <my_systemd.h>
#include "log0recv.h"
#ifdef UNIV_NONINL
......@@ -1801,6 +1803,7 @@ recv_apply_hashed_log_recs(
recv_addr_t* recv_addr;
ulint i;
ibool has_printed = FALSE;
ulong progress;
mtr_t mtr;
dberr_t err = DB_SUCCESS;
loop:
......@@ -1871,14 +1874,15 @@ loop:
}
}
progress=(ulong) (i * 100) / hash_get_n_cells(recv_sys->addr_hash);
if (has_printed
&& (i * 100) / hash_get_n_cells(recv_sys->addr_hash)
!= ((i + 1) * 100)
&& progress != ((i + 1) * 100)
/ hash_get_n_cells(recv_sys->addr_hash)) {
fprintf(stderr, "%lu ", (ulong)
((i * 100)
/ hash_get_n_cells(recv_sys->addr_hash)));
fprintf(stderr, "%lu ", progress);
sd_notifyf(0, "STATUS=Applying batch of log records for Innodb: "
"Progress %lu", progress);
}
}
......@@ -1940,6 +1944,7 @@ loop:
if (has_printed) {
fprintf(stderr, "InnoDB: Apply batch completed\n");
sd_notify(0, "STATUS=InnoDB: Apply batch completed");
}
mutex_exit(&(recv_sys->mutex));
......@@ -2089,8 +2094,11 @@ skip_this_recv_addr:
fprintf(stderr, "%lu ",
(ulong) ((100 * i) / n_hash_cells));
fflush(stderr);
sd_notifyf(0, "STATUS=Applying batch of log records for backup Innodb: "
"Progress %lu", (ulong) (100 * i) / n_hash_cells);
}
}
sd_notify(0, "STATUS=InnoDB: Apply batch for backup completed");
recv_sys_empty_hash();
}
......
......@@ -49,6 +49,9 @@ this program; if not, write to the Free Software Foundation, Inc.,
#ifdef _WIN32
#include <io.h>
#endif
#include <my_systemd.h>
/** @file ha_innodb.cc */
/* Include necessary InnoDB headers */
......@@ -21308,9 +21311,11 @@ ib_logf(
break;
case IB_LOG_LEVEL_ERROR:
sql_print_error("InnoDB: %s", str);
sd_notifyf(0, "STATUS=InnoDB: Error: %s", str);
break;
case IB_LOG_LEVEL_FATAL:
sql_print_error("InnoDB: %s", str);
sd_notifyf(0, "STATUS=InnoDB: Fatal: %s", str);
break;
}
......
......@@ -30,6 +30,8 @@ Created 9/20/1997 Heikki Tuuri
#include <stdio.h> // Solaris/x86 header file bug
#include <vector>
#include <my_systemd.h>
#include "log0recv.h"
#ifdef UNIV_NONINL
......@@ -1869,6 +1871,7 @@ recv_apply_hashed_log_recs(
recv_addr_t* recv_addr;
ulint i;
ibool has_printed = FALSE;
ulong progress;
mtr_t mtr;
dberr_t err = DB_SUCCESS;
loop:
......@@ -1939,14 +1942,15 @@ loop:
}
}
progress=(ulong) (i * 100) / hash_get_n_cells(recv_sys->addr_hash);
if (has_printed
&& (i * 100) / hash_get_n_cells(recv_sys->addr_hash)
!= ((i + 1) * 100)
&& progress != ((i + 1) * 100)
/ hash_get_n_cells(recv_sys->addr_hash)) {
fprintf(stderr, "%lu ", (ulong)
((i * 100)
/ hash_get_n_cells(recv_sys->addr_hash)));
fprintf(stderr, "%lu ", progress);
sd_notifyf(0, "STATUS=Applying batch of log records for Innodb: "
"Progress %lu", progress);
}
}
......@@ -2008,6 +2012,7 @@ loop:
if (has_printed) {
fprintf(stderr, "InnoDB: Apply batch completed\n");
sd_notify(0, "STATUS=InnoDB: Apply batch completed");
}
mutex_exit(&(recv_sys->mutex));
......@@ -2159,8 +2164,11 @@ skip_this_recv_addr:
fprintf(stderr, "%lu ",
(ulong) ((100 * i) / n_hash_cells));
fflush(stderr);
sd_notifyf(0, "STATUS=Applying batch of log records for backup Innodb: "
"Progress %lu", (ulong) (100 * i) / n_hash_cells);
}
}
sd_notify(0, "STATUS=InnoDB: Apply batch for backup completed");
recv_sys_empty_hash();
}
......
......@@ -76,7 +76,23 @@ IF(UNIX)
INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/mysql.server
DESTINATION ${inst_location} COMPONENT SupportFiles)
IF(SYSTEMD_SYSTEM_UNITDIR)
CONFIGURE_FILE(mariadb@.service.in ${CMAKE_CURRENT_BINARY_DIR}/mariadb@.service @ONLY)
# @ in directory name broken between CMake version 2.8.12.2 and 3.3
# http://public.kitware.com/Bug/view.php?id=14782
INSTALL(FILES
${CMAKE_CURRENT_SOURCE_DIR}/mariadb-bootstrap.conf
DESTINATION "${SYSTEMD_SYSTEM_UNITDIR}/mariadb@bootstrap.service.d" COMPONENT Server
)
INSTALL(FILES
${CMAKE_CURRENT_BINARY_DIR}/mariadb@.service
${CMAKE_CURRENT_SOURCE_DIR}/mariadb.service
DESTINATION ${SYSTEMD_SYSTEM_UNITDIR} COMPONENT Server
)
ENDIF()
IF (INSTALL_SYSCONFDIR)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/mysql-log-rotate DESTINATION ${INSTALL_SYSCONFDIR}/logrotate.d
RENAME mysql COMPONENT SupportFiles)
INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/mysql.server
......
#
# Install as /etc/systemd/system/mariadb@bootstrap.service.d/wsrep-new-cluster.conf
#
# This uses the multi instance version as a base.
#
[Unit]
ConditionPathExists=
[Service]
# Override the multi instance service for a bootstrap start instance
ExecStart=
ExecStart=/usr/sbin/mysqld $EXTRA_ARGS --wsrep-new-cluster
#
# /etc/systemd/system/mariadb.service
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Thanks to:
# Daniel Black
# Erkan Yanar
# David Strauss
# and probably others
[Unit]
Description=MariaDB database server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=mysql.service
Alias=mysqld.service
[Service]
##############################################################################
## Core requirements
##
Type=notify
# Setting this to true can break replication and the Type=notify settings
PrivateNetwork=false
##############################################################################
## Package maintainers
##
User=mysql
# Execute pre and post scripts as root, otherwise it does it as User=
# PermissionsStartOnly=true
# Needed to create system tables etc.
# ExecStartPre=/usr/bin/mysql_install_db
# Start main service
# EXTRA_ARGS here is for users to set in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf
# Use the [service] section and Environment="EXTRA_ARGS=...".
# This isn't a replacement for my.cnf.
ExecStart=/usr/sbin/mysqld $EXTRA_ARGS
KillMode=process
KillSignal=SIGTERM
# Don't want to see an automated SIGKILL ever
SendSIGKILL=no
# Exit status 1 is a fatal config error. Restarting won't help.
RestartPreventExitStatus=1
Restart=on-failure
RestartSec=5s
PrivateDevices=true
UMask=077
##############################################################################
## USERs can override
##
##
## by creating a file in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf
## and adding/setting the following will override this file's settings.
# Useful options not previously available in [mysqld_safe]
# Kernels like killing mysqld when out of memory because its big.
# Lets temper that preference a little.
OOMScoreAdjust=-600
# Explicitly start with high IO priority
BlockIOWeight=1000
# If you don't use the /tmp directory for SELECT ... OUTFILE and
# LOAD DATA INFILE you can enable PrivateTmp=true for a little more security.
PrivateTmp=false
##
## Options previously available to be set via [mysqld_safe]
## that now needs to be set by systemd config files as mysqld_safe
## isn't executed.
##
# Number of files limit. previously [mysqld_safe] open-file-limit
LimitNOFILE=16364
# Maximium core size. previously [mysqld_safe] core-file-size
# LimitCore=
# Nice priority. previously [mysqld_safe] nice
# Nice=-5
# Timezone. previously [mysqld_safe] timezone
# Environment="TZ=UTC"
# Library substitutions. previously [mysqld_safe] malloc-lib with explict paths
# (in LD_LIBRARY_PATH) and library name (in LD_PRELOAD).
# Environment="LD_LIBRARY_PATH=/path1 /path2" "LD_PRELOAD=
# Flush caches. previously [mysqld_safe] flush-caches=1
# ExecStartPre=sync
# ExecStartPre=sysctl -q -w vm.drop_caches=3
# numa-interleave=1 equalivant
# Change ExecStart=numactl --interleave=all /usr/sbin/mysqld......
# crash-script equalivent
# FailureAction=
# Multi instance version of mariadb. For if you run mutiple verions at once.
# Also used for mariadb@bootstrap to bootstrap Galera.
#
# create config file @INSTALL_SYSCONF2DIR@/my{instancename}.cnf
#
# start as systemctl start mariadb@{instancename}.server
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Thanks to:
# Daniel Black
# Erkan Yanar
# David Strauss
# and probably others
# Inspired from https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-db/mysql-init-scripts/files/mysqld_at.service
[Unit]
Description=MariaDB database server
After=network.target
After=syslog.target
ConditionPathExists=@INSTALL_SYSCONF2DIR@/my%I.cnf
[Install]
WantedBy=multi-user.target
Alias=mysql.service
Alias=mysqld.service
[Service]
##############################################################################
## Core requirements
##
Type=notify
# Setting this to true can break replication and the Type=notify settings
PrivateNetwork=false
##############################################################################
## Package maintainers
##
User=mysql
# Execute pre and post scripts as root, otherwise it does it as User=
# PermissionsStartOnly=true
# Needed to create system tables etc.
# ExecStartPre=/usr/bin/mysql_install_db
# Start main service
# EXTRA_ARGS here is for users to set in /etc/systemd/system/mariadb@.service.d/MY_SPECIAL.conf
# Use the [service] section and Environment="EXTRA_ARGS=...".
# This isn't a replacement for my.cnf.
ExecStart=
ExecStart=/usr/sbin/mysqld $EXTRA_ARGS --defaults-file=@INSTALL_SYSCONF2DIR@/my%I.cnf
# Alternate: (remove ConditionPathExists above)
# use [mysqld.INSTANCENAME] as sections in my.cnf
#
# ExecStart=/usr/sbin/mysqld $EXTRA_ARGS --defaults-group-suffix=%I
KillMode=process
KillSignal=SIGTERM
# Don't want to see an automated SIGKILL ever
SendSIGKILL=no
# Exit status 1 is a fatal config error. Restarting won't help.
RestartPreventExitStatus=1
Restart=on-failure
RestartSec=5s
PrivateDevices=true
UMask=077
##############################################################################
## USERs can override
##
##
## by creating a file in /etc/systemd/system/mariadb.service.d/MY_SPECIAL.conf
## and adding/setting the following will override this file's settings.
# Useful options not previously available in [mysqld_safe]
# Kernels like killing mysqld when out of memory because its big.
# Lets temper that preference a little.
OOMScoreAdjust=-600
# Explicitly start with high IO priority
BlockIOWeight=1000
# If you don't use the /tmp directory for SELECT ... OUTFILE and
# LOAD DATA INFILE you can enable PrivateTmp=true for a little more security.
PrivateTmp=false
##
## Options previously available to be set via [mysqld_safe]
## that now needs to be set by systemd config files as mysqld_safe
## isn't executed.
##
# Number of files limit. previously [mysqld_safe] open-file-limit
LimitNOFILE=16364
# Maximium core size. previously [mysqld_safe] core-file-size
# LimitCore=
# Nice priority. previously [mysqld_safe] nice
# Nice=-5
# Timezone. previously [mysqld_safe] timezone
# Environment="TZ=UTC"
# Library substitutions. previously [mysqld_safe] malloc-lib with explict paths
# (in LD_LIBRARY_PATH) and library name (in LD_PRELOAD).
# Environment="LD_LIBRARY_PATH=/path1 /path2" "LD_PRELOAD=
# Flush caches. previously [mysqld_safe] flush-caches=1
# ExecStartPre=sync
# ExecStartPre=sysctl -q -w vm.drop_caches=3
# numa-interleave=1 equalivant
# Change ExecStart=numactl --interleave=all /usr/sbin/mysqld......
# crash-script equalivent
# FailureAction=
# Make MySQL start/shutdown automatically when the machine does it.
if [ $1 = 1 ] ; then
systemd_conf=/etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
if [ -x /usr/bin/mariadb-service-convert -a ! -f "${systemd_conf}" ]; then
mkdir -p /etc/systemd/system/mariadb.service.d
/usr/bin/mariadb-service-convert > "${systemd_conf}"
fi
if [ -x /usr/bin/systemctl ] ; then
/usr/bin/systemctl daemon-reload >/dev/null 2>&1
fi
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment