Skip to content

Commit c294c25

Browse files
WL#7895 - Add systemd support to server.
The patch adds the following changes: 1. Introduce cmake option WITH_SYSTEMD. 2. Introduce server command-line option --daemonize to run server in daemon mode. 3. Introduce exit code macros MYSQLD_SUCCESS_EXIT, MYSQLD_ABORT_EXIT and MYSQLD_FAILURE_EXIT and it's related changes. 4. Auto generate mysqld.service based on install configuration 5. Install related cmake changes.
1 parent fb178c6 commit c294c25

39 files changed

+329
-553
lines changed

CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -451,6 +451,17 @@ ENDIF()
451451

452452
INCLUDE(cmake/boost.cmake)
453453

454+
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
455+
OPTION(WITH_SYSTEMD "Enable installation of systemd support files" OFF)
456+
IF (WITH_SYSTEMD)
457+
INCLUDE(cmake/systemd.cmake)
458+
ENDIF()
459+
ELSE()
460+
IF (WITH_SYSTEMD)
461+
MESSAGE(FATAL_ERROR "Installation of systemd support files not supported")
462+
ENDIF()
463+
ENDIF()
464+
454465
# Run platform tests
455466
INCLUDE(configure.cmake)
456467

include/my_dbug.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -125,13 +125,13 @@ extern const char* _db_get_func_(void);
125125
#else
126126
/*
127127
Avoid popup with abort/retry/ignore buttons. When BUG#31745 is fixed we can
128-
call abort() instead of _exit(3) (now it would cause a "test signal" popup).
128+
call abort() instead of _exit(2) (now it would cause a "test signal" popup).
129129
*/
130130
#include <crtdbg.h>
131131
#define DBUG_ABORT() (_db_flush_(),\
132132
(void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE),\
133133
(void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR),\
134-
_exit(3))
134+
_exit(2))
135135
#endif
136136
#define DBUG_CHECK_CRASH(func, op) \
137137
do { char _dbuf_[255]; strxnmov(_dbuf_, sizeof(_dbuf_)-1, (func), (op)); \

mysql-test/lib/My/SafeProcess.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- cperl -*-
2-
# Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2007, 2015 Oracle and/or its affiliates. All rights reserved.
33
#
44
# This program is free software; you can redistribute it and/or
55
# modify it under the terms of the GNU Library General Public
@@ -140,6 +140,9 @@ sub new {
140140
my $shutdown = delete($opts{'shutdown'});
141141
my $user_data= delete($opts{'user_data'});
142142
my $envs = delete($opts{'envs'});
143+
my $daemon_mode = delete($opts{'daemon_mode'});
144+
my $pid_file= delete($opts{'pid_file'})
145+
if defined $daemon_mode && $daemon_mode == 1;
143146

144147
# if (defined $host) {
145148
# $safe_script= "lib/My/SafeProcess/safe_process_cpcd.pl";
@@ -188,6 +191,8 @@ sub new {
188191
error => $error,
189192
append => $opts{append},
190193
args => \@safe_args,
194+
pid_file => $pid_file
195+
191196
);
192197

193198
my $name = delete($opts{'name'}) || "SafeProcess$pid";

mysql-test/lib/My/SafeProcess/Base.pm

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- cperl -*-
2-
# Copyright (c) 2007 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
2+
# Copyright (c) 2007, 2015 Oracle and/or its affiliates. All rights reserved.
33
# Use is subject to license terms.
44
#
55
# This program is free software; you can redistribute it and/or modify
@@ -107,7 +107,7 @@ sub create_process {
107107
my $input = delete($opts{'input'});
108108
my $output = delete($opts{'output'});
109109
my $error = delete($opts{'error'});
110-
110+
my $pid_file = delete($opts{'pid_file'});
111111
my $open_mode= $opts{append} ? ">>" : ">";
112112

113113
if ($^O eq "MSWin32"){
@@ -176,6 +176,14 @@ sub create_process {
176176
# Parent
177177
$pipe->reader();
178178
my $line= <$pipe>; # Wait for child to say it's ready
179+
# if pid-file is defined, read process id from pid-file.
180+
if ( defined $pid_file ) {
181+
sleep 1 until -e $pid_file;
182+
open FILE, $pid_file;
183+
chomp(my $pid_val = <FILE>);
184+
close FILE;
185+
return $pid_val
186+
}
179187
return $pid;
180188
}
181189

@@ -206,13 +214,12 @@ sub create_process {
206214
}
207215
}
208216

209-
# Tell parent to continue
210-
$pipe->writer();
211-
print $pipe "ready\n";
212-
213217
if ( !exec($path, @$args) ){
214218
croak("Failed to exec '$path': $!");
215219
}
220+
# Tell parent to continue
221+
$pipe->writer();
222+
print $pipe "ready\n";
216223

217224
croak("Should never come here");
218225

mysql-test/mysql-test-run.pl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5453,6 +5453,11 @@ ($$$)
54535453
# We can get an empty argument when we set environment variables to ""
54545454
# (e.g plugin not found). Just skip it.
54555455
}
5456+
elsif ($arg eq "--daemonize")
5457+
{
5458+
$mysqld->{'daemonize'}= 1;
5459+
mtr_add_arg($args, "%s", $arg);
5460+
}
54565461
else
54575462
{
54585463
mtr_add_arg($args, "%s", $arg);
@@ -5577,6 +5582,8 @@ ($$)
55775582
host => undef,
55785583
shutdown => sub { mysqld_stop($mysqld) },
55795584
envs => \@opt_mysqld_envs,
5585+
pid_file => $mysqld->value('pid-file'),
5586+
daemon_mode => $mysqld->{'daemonize'}
55805587
);
55815588
mtr_verbose("Started $mysqld->{proc}");
55825589
}

mysql-test/r/mysqld--help-notwin.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ The following options may be given as the first argument:
166166
--console Write error output on screen; don't remove the console
167167
window on windows.
168168
--core-file Write core on errors.
169+
--daemonize Run mysqld as sysv daemon
169170
-h, --datadir=name Path to the database root directory
170171
--date-format=name The DATE format (ignored)
171172
--datetime-format=name
@@ -1190,6 +1191,7 @@ completion-type NO_CHAIN
11901191
concurrent-insert AUTO
11911192
connect-timeout 10
11921193
console FALSE
1194+
daemonize FALSE
11931195
date-format %Y-%m-%d
11941196
datetime-format %Y-%m-%d %H:%i:%s
11951197
default-authentication-plugin mysql_native_password

mysql-test/suite/innodb/t/log_file.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let SEARCH_PATTERN=\[ERROR\] Aborting;
5959
# complaining about mysql.* tables. This is sufficient for testing
6060
# missing tablespaces.
6161
--echo # Start mysqld to create tablespaces according to my.cnf
62-
--error 2
62+
--error 1
6363
--exec $MYSQLD $args --skip-grant-tables --innodb-unknown-parameter
6464
let SEARCH_PATTERN=unknown option '--innodb-unknown-parameter';
6565
--source include/search_pattern_in_file.inc

mysql-test/suite/innodb/t/log_file_name.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ let SEARCH_PATTERN= InnoDB: Tablespace \d+ was not found at .*t[12].ibd.
106106
# Create a short file.
107107
--exec echo "" > $MYSQLD_DATADIR/test/t2.ibd
108108

109-
--error 3
109+
--error 2
110110
--exec $mysqld
111111

112112
# TODO: Look for the file name in error message.
@@ -187,7 +187,7 @@ EOF
187187

188188
--copy_file $MYSQLD_DATADIR/test/u6.ibd $MYSQLD_DATADIR/test/u4.ibd
189189

190-
--error 3
190+
--error 2
191191
--exec $mysqld --innodb-force-recovery=1
192192

193193
let SEARCH_PATTERN= \[ERROR\] InnoDB: Header page consists of zero bytes in datafile: .*u1.ibd;
@@ -228,7 +228,7 @@ let SEARCH_PATTERN= \[ERROR\] InnoDB: Cannot replay rename '.*u5.ibd' to '.*u6.i
228228

229229
--remove_file $MYSQLD_DATADIR/test/u6.ibd
230230

231-
--error 2
231+
--error 1
232232
--exec $mysqld --innodb-force-recovery=1 --innodb-nonexistent-option
233233
let SEARCH_PATTERN= \[ERROR\] unknown option '--innodb-nonexistent-option';
234234
--source include/search_pattern_in_file.inc

mysql-test/suite/perfschema/t/bad_option.test

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect;
1616
--exec echo "wait" > $restart_file
1717
--shutdown_server
1818
--source include/wait_until_disconnected.inc
19-
20-
--error 7
19+
--error 1
2120
--exec $MYSQLD_CMD --loose-console --performance-schema-enabled=maybe > $error_log 2>&1
2221
# The server restart aborts
2322
# [ERROR] unknown variable 'performance-schema-enabled=maybe'
@@ -26,7 +25,7 @@ let SEARCH_PATTERN= \[ERROR\] unknown variable 'performance-schema-enabled=maybe
2625
--echo # Server start with invalid startup option value 'performance-schema-enabled=maybe' : pass
2726

2827
--remove_file $error_log
29-
--error 7
28+
--error 1
3029
--exec $MYSQLD_CMD --loose-console --performance-schema-max_=12 > $error_log 2>&1
3130
# The server restart aborts
3231
# [ERROR] unknown variable 'performance-schema-max_=12'
@@ -42,7 +41,7 @@ let SEARCH_PATTERN= \[ERROR\] unknown variable 'performance-schema-max_=12';
4241
# a similar reaction.
4342

4443
--remove_file $error_log
45-
--error 2
44+
--error 1
4645
--exec $MYSQLD_CMD --loose-console --performance-schema-unknown_99 > $error_log 2>&1
4746
# The server restart aborts
4847
let SEARCH_PATTERN= \[ERROR\] unknown option '--performance-schema-unknown_99';

mysql-test/t/mysqld_safe.test

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
--source include/have_mysqld_safe.inc
12
--source include/not_embedded.inc
23
--source include/not_windows.inc
34

@@ -30,49 +31,46 @@ EOF
3031
#Remove the temp file
3132
--remove_file $MYSQLTEST_VARDIR/tmp/mysqld_path_file.inc
3233

33-
# 2) Insert a check if mysqld_safe is existing.
34-
--file_exists $MYSQLD_SAFE
35-
36-
# 3) Shutdown mysqld which is started by mtr.
34+
# 2) Shutdown mysqld which is started by mtr.
3735
--let $_server_id= `SELECT @@server_id`
3836
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$_server_id.expect
3937
--exec echo "wait" > $_expect_file_name
4038
--shutdown_server
4139
--source include/wait_until_disconnected.inc
4240

4341

44-
# 4) Run the mysqld_safe script with exec.
45-
--exec sh $MYSQLD_SAFE --defaults-file=$MYSQLTEST_VARDIR/my.cnf --log-error=$MYSQLTEST_VARDIR/log/err.log --basedir=$MYSQL_BASEDIR --ledir=$mysqld_path --datadir=$MYSQLD_DATADIR --secure-file-priv=$MYSQLTEST_VARDIR --socket=$MYSQL_SOCKET --pid-file=$MYSQL_PIDFILE --port=$MYSQL_PORT --timezone=SYSTEM --log-output=file --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 < /dev/null > /dev/null 2>&1 &
42+
# 3) Run the mysqld_safe script with exec.
43+
--exec sh $MYSQLD_SAFE --defaults-file=$MYSQLTEST_VARDIR/my.cnf --log-error=$MYSQLTEST_VARDIR/log/err.log --basedir=$MYSQL_BASEDIR --ledir=$mysqld_path --datadir=$MYSQLD_DATADIR --socket=$MYSQL_SOCKET --pid-file=$MYSQL_PIDFILE --port=$MYSQL_PORT --timezone=SYSTEM --log-output=file --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 < /dev/null > /dev/null 2>&1 &
4644

4745
# mysqld_safe takes some time to start mysqld
4846
--enable_reconnect
4947
--source include/wait_until_connected_again.inc
5048
--disable_reconnect
5149

52-
# 5) Reconnect to mysqld again
50+
# 4) Reconnect to mysqld again
5351
connection default;
5452

55-
# 6) Execute some SQL
53+
# 5) Execute some SQL
5654
--exec $MYSQL -h localhost -S $MYSQL_SOCKET -P $MYSQL_PORT -u root -e "SHOW DATABASES" 2>&1
5755

58-
# 7) Kill mysqld, which must be restarted now automaticly by mysqld_safe
56+
# 6) Kill mysqld, which must be restarted now automaticly by mysqld_safe
5957
--exec sh $MYSQL_TEST_DIR/t/mysqld_safe.sh $MYSQL_PIDFILE 2>&1
6058

6159
# mysqld_safe takes some time to restart mysqld
6260
--enable_reconnect
6361
--source include/wait_until_connected_again.inc
6462
--disable_reconnect
6563

66-
# 8) Execute some SQL
64+
# 7) Execute some SQL
6765
--exec $MYSQL -h localhost -S $MYSQL_SOCKET -P $MYSQL_PORT -u root -e "SHOW DATABASES" 2>&1
6866

69-
# 9) Shutdown mysqld with mysqladmin
67+
# 8) Shutdown mysqld with mysqladmin
7068
--exec $MYSQLADMIN -h localhost -S $MYSQL_SOCKET -P $MYSQL_PORT -u root shutdown 2>&1
7169

7270
# Delay introduced - mysqld_safe takes some time to restart mysqld
7371
--source include/wait_until_disconnected.inc
7472

75-
# 10) Restart mysqld of mtr
73+
# 9) Restart mysqld of mtr
7674
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
7775
--enable_reconnect
7876
--source include/wait_until_connected_again.inc

0 commit comments

Comments
 (0)