Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ INCLUDE(pcre)
INCLUDE(ctest)
INCLUDE(plugin)
INCLUDE(install_macros)
INCLUDE(systemd)
INCLUDE(mysql_add_executable)

# Handle options
Expand Down Expand Up @@ -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})
Expand Down
56 changes: 56 additions & 0 deletions cmake/systemd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
INCLUDE(FindPkgConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if you could add copyright header to this file. And also to my_systemd.h.

# 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)
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()
1 change: 1 addition & 0 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,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

Expand Down
3 changes: 2 additions & 1 deletion debian/dist/Debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Build-Depends: procps | hurd, debhelper, libncurses5-dev (>= 5.0-6),
libpam0g-dev, psmisc, po-debconf, chrpath,
dpatch, gawk, bison, lsb-release, hardening-wrapper,
cmake (>= 2.7), libaio-dev, ${MAYBE_LIBCRACK}
libjemalloc-dev (>= 3.0.0)
libjemalloc-dev (>= 3.0.0),
libsystemd-daemon-dev | libsystemd-dev, dh-systemd
Standards-Version: 3.8.3
Homepage: http://mariadb.org/
Vcs-Browser: https://github.com/MariaDB/server/tree/10.1/
Expand Down
2 changes: 2 additions & 0 deletions debian/dist/Debian/mariadb-server-10.1.files.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ usr/bin/wsrep_sst_mysqldump
usr/bin/wsrep_sst_rsync
usr/bin/wsrep_sst_xtrabackup
usr/bin/wsrep_sst_xtrabackup-v2
usr/bin/mariadb-socket-convert
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
Expand Down
13 changes: 13 additions & 0 deletions debian/dist/Debian/mariadb-server-10.1.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ if [ "$1" = "configure" ]; then
db_go
fi

# create a systemd socket activation file based on current settings
systemd_sockconf=/etc/systemd/system/mariadb.socket.d/migrated-from-my.cnf-settings.conf
if [ -x /usr/bin/mariadb-socket-convert -a ! -f "${systemd_sockconf}" ]; then
mkdir -p /etc/systemd/system/mariadb.socket.d
/usr/bin/mariadb-socket-convert > "${systemd_sockconf}"
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be only called in case of "configure"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is. Scroll up to line 247.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed this somehow. :(


db_stop # in case invoke failes
Expand Down
6 changes: 6 additions & 0 deletions debian/dist/Debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ 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-socket-convert $(TMP)/usr/bin/
install -m 0755 scripts/mariadb-service-convert $(TMP)/usr/bin/

# mariadb-test
mv $(TMP)/usr/mysql-test $(TMP)/usr/share/mysql

Expand Down Expand Up @@ -216,7 +220,9 @@ binary-indep: build install
dh_installexamples -i
dh_installmenu -i
dh_installlogrotate -i
dh_systemd_enable -i support-files/mariadb.service support-files/mariadb.socket
dh_installinit -i
dh_systemd_start -i --restart-after-upgrade mariadb.socket
dh_installcron -i
dh_installman -i
dh_installinfo -i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this change (and many other changes) will break packaging on older supported systems with no systemd. But I have no reasonable alternative on my mind, so probably let's do it now and fix later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its the approach suggested by the debian packaging guide. I assume handling of non-systemd is wrapped under dh_systemd_start somehow.

Expand Down
3 changes: 2 additions & 1 deletion debian/dist/Ubuntu/control
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Build-Depends: procps | hurd, debhelper, libncurses5-dev (>= 5.0-6),
libpam0g-dev, psmisc, po-debconf, chrpath,
dpatch, gawk, bison, lsb-release, hardening-wrapper,
cmake (>= 2.7), libaio-dev, ${MAYBE_LIBCRACK}
libjemalloc-dev (>= 3.0.0)
libjemalloc-dev (>= 3.0.0),
libsystemd-daemon-dev | libsystemd-dev, dh-systemd
Standards-Version: 3.8.2
Homepage: http://mariadb.org/
Vcs-Browser: http://bazaar.launchpad.net/~maria-captains/maria/10.1/files
Expand Down
2 changes: 2 additions & 0 deletions debian/dist/Ubuntu/mariadb-server-10.1.files.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ usr/bin/wsrep_sst_mysqldump
usr/bin/wsrep_sst_rsync
usr/bin/wsrep_sst_xtrabackup
usr/bin/wsrep_sst_xtrabackup-v2
usr/bin/mariadb-socket-convert
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
Expand Down
12 changes: 12 additions & 0 deletions debian/dist/Ubuntu/mariadb-server-10.1.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ if [ "$1" = "configure" ]; then
db_go
fi

# create a systemd socket activation file based on current settings
systemd_sockconf=/etc/systemd/system/mariadb.socket.d/migrated-from-my.cnf-settings.conf
if [ -x /usr/bin/mariadb-socket-convert -a ! -f "${systemd_sockconf}" ]; then
mkdir -p /etc/systemd/system/mariadb.socket.d
/usr/bin/mariadb-socket-convert > "${systemd_sockconf}"
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
Expand Down
6 changes: 6 additions & 0 deletions debian/dist/Ubuntu/rules
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ 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-socket-convert $(TMP)/usr/bin/
install -m 0755 scripts/mariadb-service-convert $(TMP)/usr/bin/

# mariadb-test
mv $(TMP)/usr/mysql-test $(TMP)/usr/share/mysql

Expand Down Expand Up @@ -221,7 +225,9 @@ binary-indep: build install
dh_installexamples -i
dh_installmenu -i
dh_installlogrotate -i
dh_systemd_enable -i support-files/mariadb.service support-files/mariadb.socket
dh_installinit -i
dh_systemd_start -i --restart-after-upgrade mariadb.socket
dh_installcron -i
dh_installman -i
dh_installinfo -i
Expand Down
17 changes: 17 additions & 0 deletions include/my_systemd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#ifndef MY_SYSTEMD_INCLUDED
#define MY_SYSTEMD_INCLUDED

#ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h>

#else

#define sd_listen_fds(X) (0)

#define sd_notify(X, Y)
#define sd_notifyf(E, F, ...)

#endif

#endif /* MY_SYSTEMD_INCLUDED */
38 changes: 38 additions & 0 deletions include/mysql/psi/mysql_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ inline_mysql_socket_set_state(MYSQL_SOCKET socket, enum PSI_socket_state state)
}
#endif /* HAVE_PSI_SOCKET_INTERFACE */

/**
@def mysql_socket_fd(K, F)
Create a socket.
@c mysql_socket_fd is a replacement for @c socket.
@param K PSI_socket_key for this instrumented socket
@param F File descriptor
*/

#ifdef HAVE_PSI_SOCKET_INTERFACE
#define mysql_socket_fd(K, F) \
inline_mysql_socket_fd(K, F)
#else
#define mysql_socket_fd(K, F) \
inline_mysql_socket_fd(F)
#endif

/**
@def mysql_socket_socket(K, D, T, P)
Create a socket.
Expand Down Expand Up @@ -542,6 +558,28 @@ static inline void inline_mysql_socket_register(
}
#endif

/** mysql_socket_fd */

static inline MYSQL_SOCKET
inline_mysql_socket_fd
(
#ifdef HAVE_PSI_SOCKET_INTERFACE
PSI_socket_key key,
#endif
int fd)
{
MYSQL_SOCKET mysql_socket= MYSQL_INVALID_SOCKET;
mysql_socket.fd= fd;
#ifdef HAVE_PSI_SOCKET_INTERFACE
if (likely(mysql_socket.fd != INVALID_SOCKET))
{
mysql_socket.m_psi= PSI_SOCKET_CALL(init_socket)
(key, (const my_socket*)&mysql_socket.fd, NULL, 0);
}
#endif
return mysql_socket;
}

/** mysql_socket_socket */

static inline MYSQL_SOCKET
Expand Down
2 changes: 2 additions & 0 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ ELSE()
mysqld_multi
mysqld_safe
${WSREP_BINARIES}
mariadb-service-convert
mariadb-socket-convert
)
FOREACH(file ${BIN_SCRIPTS})
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.sh)
Expand Down
63 changes: 63 additions & 0 deletions scripts/mariadb-service-convert
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
#
# 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

. /usr/bin/mysqld_safe --simulate

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}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You emit ExecStart only if numa-interleave is set. Does that mean "if numa-interleave is not set use default ExecStart specified by mariadb.service"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

echo
fi

[ -n "${CRASH_SCRIPT}" ] && echo FailureAction=${CRASH_SCRIPT}
Loading