Skip to content

Commit fd6ec95

Browse files
WL#7895 - Add systemd support to server.
Post Push Fix - Add newly added files (missed because of some merge issues).
1 parent c294c25 commit fd6ec95

12 files changed

+414
-7
lines changed

cmake/systemd.cmake

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
13+
# systemd support files shall be installed on linux if the build host machine
14+
# has systemd package installed. make install will install the systemd
15+
# related configuration files into the systemd service files directories. To
16+
# use systemd the system needs to be booted with init as systemd.
17+
18+
MACRO(MYSQL_CHECK_SYSTEMD)
19+
FIND_PACKAGE(PkgConfig QUIET)
20+
IF(PKG_CONFIG_FOUND)
21+
PKG_CHECK_MODULES(SYSTEMD "systemd")
22+
23+
IF(SYSTEMD_FOUND)
24+
EXECUTE_PROCESS(COMMAND ${PKG_CONFIG_EXECUTABLE}
25+
--variable=systemdsystemunitdir systemd
26+
OUTPUT_VARIABLE SYSTEMD_SERVICES_DIR)
27+
STRING(REGEX REPLACE "[ \t\n]+" ""
28+
SYSTEMD_SERVICES_DIR "${SYSTEMD_SERVICES_DIR}")
29+
IF("${SYSTEMD_SERVICES_DIR}" STREQUAL "")
30+
SET(SYSTEMD_SERVICES_DIR "/usr/lib/systemd/system")
31+
ENDIF()
32+
MESSAGE(STATUS "SYSTEMD_SERVICES_DIR ${SYSTEMD_SERVICES_DIR}")
33+
EXECUTE_PROCESS(COMMAND ${PKG_CONFIG_EXECUTABLE}
34+
--variable=tmpfilesdir systemd
35+
OUTPUT_VARIABLE SYSTEMD_TMPFILES_DIR)
36+
STRING(REGEX REPLACE "[ \t\n]+" ""
37+
SYSTEMD_TMPFILES_DIR "${SYSTEMD_TMPFILES_DIR}")
38+
IF ("${SYSTEMD_TMPFILES_DIR}" STREQUAL "")
39+
SET(SYSTEMD_TMPFILES_DIR "/usr/lib/tmpfiles.d")
40+
ENDIF()
41+
MESSAGE(STATUS "SYSTEMD_TMPFILES_DIR ${SYSTEMD_TMPFILES_DIR}")
42+
ELSE()
43+
MESSAGE(FATAL_ERROR "Unable to detect systemd support on build machine,\
44+
Aborting cmake build.")
45+
ENDIF()
46+
ELSE()
47+
MESSAGE(FATAL_ERROR, "Unable to detect systemd support on build machine,\
48+
Aborting cmake build.")
49+
ENDIF()
50+
51+
IF("${SYSTEMD_SERVICE_NAME}" STREQUAL "")
52+
SET(SYSTEMD_SERVICE_NAME "mysqld")
53+
ENDIF()
54+
MESSAGE(STATUS "SYSTEMD_SERVICE_NAME ${SYSTEMD_SERVICE_NAME}")
55+
56+
IF("${SYSTEMD_PID_DIR}" STREQUAL "")
57+
SET(SYSTEMD_PID_DIR "/var/run/mysqld")
58+
ENDIF()
59+
MESSAGE(STATUS "SYSTEMD_PID_DIR ${SYSTEMD_PID_DIR}")
60+
ENDMACRO()
61+
62+
MESSAGE(STATUS "Enabling installation of systemd support files...")
63+
MYSQL_CHECK_SYSTEMD()

mysql-test/r/daemonize_opt.result

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT 1;
2+
1
3+
1

mysql-test/r/mysqld_daemon.result

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Database
2+
information_schema
3+
mtr
4+
mysql
5+
performance_schema
6+
test

mysql-test/t/daemonize_opt-master.opt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--daemonize

mysql-test/t/daemonize_opt.test

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Start mysqld under mtr by specifying --daemonize option in an opt file
3+
#
4+
--source include/not_embedded.inc
5+
--source include/not_windows.inc
6+
--source include/not_valgrind.inc
7+
8+
SELECT 1;

mysql-test/t/mysqld_daemon.test

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Test for starting mysqld using --daemonize option.
3+
#
4+
5+
--source include/not_embedded.inc
6+
--source include/not_windows.inc
7+
--source include/not_valgrind.inc
8+
9+
# Set valiables to be used in parameters of mysqld.
10+
let $MYSQLD_DATADIR= `SELECT @@datadir`;
11+
let $MYSQL_BASEDIR= `SELECT @@basedir`;
12+
let $MYSQL_SOCKET= `SELECT @@socket`;
13+
let $MYSQL_TIMEZONE= `SELECT @@time_zone`;
14+
let $MYSQL_PIDFILE= `SELECT @@pid_file`;
15+
let $MYSQL_PORT= `SELECT @@port`;
16+
let $MYSQL_MESSAGESDIR= `SELECT @@lc_messages_dir`;
17+
let $start_page_size= `SELECT @@innodb_page_size`;
18+
let $other_page_size_k= `SELECT $start_page_size DIV 1024`;
19+
let $other_page_size_nk= `SELECT CONCAT($other_page_size_k,'k')`;
20+
21+
# Shutdown mysqld which is started by mtr.
22+
--let $_server_id= `SELECT @@server_id`
23+
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect
24+
--exec echo "wait" > $_expect_file_name
25+
--shutdown_server
26+
--source include/wait_until_disconnected.inc
27+
28+
# Run the mysqld with exec with --daemonize option.
29+
--exec $MYSQLD --defaults-file=$MYSQLTEST_VARDIR/my.cnf --basedir=$MYSQL_BASEDIR --datadir=$MYSQLD_DATADIR --socket=$MYSQL_SOCKET --pid-file=$MYSQL_PIDFILE --port=$MYSQL_PORT --loose-debug-sync-timeout=600 --default-storage-engine=InnoDB --default-tmp-storage-engine=InnoDB --loose-skip-log-bin --core-file --lc-messages-dir=$MYSQL_MESSAGESDIR --innodb-page-size=$other_page_size_nk --daemonize --secure-file-priv="" >$MYSQLTEST_VARDIR/log/mysqld_out_err.log 2>&1
30+
31+
# mysqld takes some time to come up.
32+
--enable_reconnect
33+
--source include/wait_until_connected_again.inc
34+
--disable_reconnect
35+
36+
# Execute some SQL
37+
--exec $MYSQL -h localhost -S $MYSQL_SOCKET -P $MYSQL_PORT -u root -e "SHOW DATABASES" 2>&1
38+
39+
# Shutdown mysqld with mysqladmin
40+
--exec $MYSQLADMIN -h localhost -S $MYSQL_SOCKET -P $MYSQL_PORT -u root shutdown 2>&1
41+
42+
# Delay introduced - mysqld_safe takes some time to restart mysqld
43+
--source include/wait_until_disconnected.inc
44+
45+
# Restart mysqld of mtr
46+
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
47+
--enable_reconnect
48+
--source include/wait_until_connected_again.inc

packaging/rpm-fedora/mysql.spec.in

+2-7
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ datadir=$(/usr/bin/my_print_defaults server mysqld | grep '^--datadir=' | sed -n
577577
%attr(755, root, root) %{_bindir}/mysql_install_db
578578
%attr(755, root, root) %{_bindir}/mysql_plugin
579579
%attr(755, root, root) %{_bindir}/mysql_secure_installation
580+
%attr(755, root, root) %{_bindir}/mysql_ssl_rsa_setup
580581
%attr(755, root, root) %{_bindir}/mysql_tzinfo_to_sql
581582
%attr(755, root, root) %{_bindir}/mysql_upgrade
582583
%attr(755, root, root) %{_bindir}/mysqldumpslow
@@ -585,8 +586,6 @@ datadir=$(/usr/bin/my_print_defaults server mysqld | grep '^--datadir=' | sed -n
585586
%attr(755, root, root) %{_bindir}/resolve_stack_dump
586587
%attr(755, root, root) %{_bindir}/resolveip
587588
%attr(755, root, root) %{_bindir}/mysqld_pre_systemd
588-
%attr(755, root, root) %{_bindir}/mysql_ssl_rsa_setup
589-
%attr(755, root, root) %{_bindir}/mysql-systemd-start
590589
%attr(755, root, root) %{_sbindir}/mysqld
591590
%attr(755, root, root) %{_sbindir}/mysqld-debug
592591

@@ -785,12 +784,7 @@ datadir=$(/usr/bin/my_print_defaults server mysqld | grep '^--datadir=' | sed -n
785784
%attr(755, root, root) %{_libdir}/mysql/libmysqld.so
786785

787786
%changelog
788-
<<<<<<< HEAD
789-
* Wed Oct 29 2014 Balasubramanian Kandasamy <balasubramanian.kandasamy@oracle.com> - 5.7.6-0.2.m16
790-
- Use native systemd support
791-
=======
792787
* Tue Feb 3 2015 Balasubramanian Kandasamy <balasubramanian.kandasamy@oracle.com> - 5.7.6-0.2.m16
793-
>>>>>>> mysql-trunk
794788
- Include boost sources
795789
- Add license info in each subpackage
796790
- Remove systemd conditional
@@ -800,6 +794,7 @@ datadir=$(/usr/bin/my_print_defaults server mysqld | grep '^--datadir=' | sed -n
800794
- Updated default shell for mysql user
801795
- Added mysql_ssl_rsa_setup
802796
- Include mysql-files directory
797+
- Use native systemd support
803798

804799
* Thu Sep 18 2014 Balasubramanian Kandasamy <balasubramanian.kandasamy@oracle.com> - 5.7.6-0.2.m16
805800
- Provide replication_observers_example_plugin.so plugin

scripts/systemd/mysqld.service.in

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
#
16+
# systemd service file for MySQL forking server
17+
#
18+
19+
[Unit]
20+
Description=MySQL Server
21+
After=network.target
22+
After=syslog.target
23+
24+
[Install]
25+
WantedBy=multi-user.target
26+
27+
[Service]
28+
User=@MYSQLD_USER@
29+
Group=@MYSQLD_USER@
30+
31+
Type=forking
32+
33+
PIDFile=@SYSTEMD_PID_DIR@/mysqld.pid
34+
35+
# Execute pre and post scripts as root
36+
PermissionsStartOnly=true
37+
38+
# Needed to create system tables
39+
ExecStartPre=@bindir@/mysqld_pre_systemd
40+
41+
# Start main service
42+
ExecStart=@libexecdir@/mysqld --daemonize
43+
44+
# Use this to switch malloc implementation
45+
EnvironmentFile=-/etc/sysconfig/mysql
46+
47+
Restart=on-failure
48+
49+
RestartPreventExitStatus=1
50+
51+
PrivateTmp=false

scripts/systemd/mysqld.tmpfiles.d.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
2+
d @SYSTEMD_PID_DIR@ 0755 @MYSQLD_USER@ @MYSQLD_USER@ -

scripts/systemd/mysqld_pre_systemd.in

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#! /bin/bash
2+
3+
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation; version 2 of the License.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
18+
19+
# Script used by systemd @SYSTEMD_SERVICE_NAME@.service to run before executing mysqld
20+
21+
get_option () {
22+
local section=$1
23+
local option=$2
24+
local default=$3
25+
ret=$(@bindir@/my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-)
26+
[ -z $ret ] && ret=$default
27+
echo $ret
28+
}
29+
30+
install_db () {
31+
# Note: something different than datadir=/var/lib/mysql requires SELinux policy changes (in enforcing mode)
32+
datadir=$(get_option mysqld datadir "@MYSQL_DATADIR@")
33+
log=$(get_option mysqld log-error /var/log/mysqld.log)
34+
35+
# Restore log, dir, perms and SELinux contexts
36+
37+
[ -d "$datadir" ] || install -d -m 0755 -o@MYSQLD_USER@ -g@MYSQLD_USER@ "$datadir" || exit 1
38+
39+
[ -e $log ] || touch $log
40+
chmod 0640 $log
41+
chown @MYSQLD_USER@:@MYSQLD_USER@ $log || exit 1
42+
43+
if [ -x /usr/sbin/restorecon ]; then
44+
/usr/sbin/restorecon "$datadir"
45+
/usr/sbin/restorecon $log
46+
fi
47+
48+
# If special mysql dir is in place, skip db install
49+
[ -d "$datadir/mysql" ] && exit 0
50+
51+
# Create initial db
52+
@bindir@/mysql_install_db --datadir="$datadir" --user=@MYSQLD_USER@
53+
exit 0
54+
}
55+
install_db
56+
57+
exit 0

0 commit comments

Comments
 (0)