Merge pull request #13658 from miska/mariadb-procd
mariadb: procd adoption
This commit is contained in:
commit
2415ab0e5b
|
@ -137,8 +137,7 @@ MARIADB_SERVER := \
|
|||
mysql_install_db \
|
||||
mysql_upgrade \
|
||||
mysqladmin \
|
||||
mysqld \
|
||||
mysqld_safe
|
||||
mysqld
|
||||
|
||||
MARIADB_SERVER_EXTRA := \
|
||||
aria_chk \
|
||||
|
@ -157,6 +156,7 @@ MARIADB_SERVER_EXTRA := \
|
|||
mysql_setpermission \
|
||||
mysql_tzinfo_to_sql \
|
||||
mysqld_multi \
|
||||
mysqld_safe \
|
||||
mysqld_safe_helper \
|
||||
mysqldumpslow \
|
||||
mysqlhotcopy \
|
||||
|
@ -380,7 +380,7 @@ CMAKE_OPTIONS += \
|
|||
-DINSTALL_SQLBENCHDIR="" \
|
||||
-DINSTALL_SUPPORTFILESDIR=share/mariadb \
|
||||
-DINSTALL_UNIX_ADDRDIR=$(MARIADB_SOCKET) \
|
||||
-DMYSQL_DATADIR=/var/lib/mysql \
|
||||
-DMYSQL_DATADIR=/srv/mysql \
|
||||
-DMYSQL_UNIX_ADDR=$(MARIADB_SOCKET) \
|
||||
-DSKIP_TESTS=ON \
|
||||
-DWITH_DEBUG=OFF \
|
||||
|
|
|
@ -5,15 +5,19 @@
|
|||
START=95
|
||||
# shellcheck disable=SC2034
|
||||
STOP=10
|
||||
# shellcheck disable=SC2034
|
||||
USE_PROCD=1
|
||||
|
||||
NAME=mysqld
|
||||
my_user="mariadb"
|
||||
my_group="mariadb"
|
||||
|
||||
LOGGER="/usr/bin/logger -p user.err -s -t $NAME --"
|
||||
[ -x "$LOGGER" ] || LOGGER="echo"
|
||||
|
||||
MYSQLADMIN="/usr/bin/mysqladmin"
|
||||
MYSQLD="/usr/bin/$NAME"
|
||||
MYSQLDSAFE="/usr/bin/mysqld_safe"
|
||||
|
||||
pidfile=""
|
||||
|
||||
# mysqladmin likes to read /root/.my.cnf which could cause issues.
|
||||
export HOME="/etc/mysql"
|
||||
|
@ -22,35 +26,39 @@ export HOME="/etc/mysql"
|
|||
cd /
|
||||
|
||||
mysqld_get_param() {
|
||||
$MYSQLD --print-defaults \
|
||||
| tr " " "\n" \
|
||||
| grep -- "--$1" \
|
||||
| tail -n 1 \
|
||||
| cut -d= -f2
|
||||
"$MYSQLD" --help --verbose | sed -n 's|^'"$1"'[[:blank:]]\+||p'
|
||||
}
|
||||
|
||||
# Send kill signal to MariaDB process
|
||||
#
|
||||
# Usage: boolean mysqld_kill signal
|
||||
mysql_kill() {
|
||||
[ -n "$pidfile" ] || pidfile="$(mysqld_get_param pid-file)"
|
||||
[ -f "$pidfile" ] || return 1
|
||||
pid="$(cat "$pidfile")"
|
||||
[ -n "$pid" ] || return 2
|
||||
kill "$1" "$pid"
|
||||
}
|
||||
|
||||
# Checks if a server is running and accessible.
|
||||
#
|
||||
# check_alive insists on a pingable server
|
||||
# check_dead also fails if there is a lost mysqld in the process list
|
||||
# Supported modes are 'check_alive' and 'check_dead'.
|
||||
# Both check for pidfile and whether the specified process is running and is
|
||||
# indeed mysqld. We could use mysqladmin for the check, but to be able to do
|
||||
# so, mysqladmin requires access to the database, which sounds like overkill
|
||||
# and potential security issue.
|
||||
#
|
||||
# Usage: boolean mysqld_status [check_alive|check_dead]
|
||||
mysqld_status() {
|
||||
if $MYSQLADMIN ping >/dev/null 2>&1; then
|
||||
ping_alive=1
|
||||
else
|
||||
ping_alive=0
|
||||
fi
|
||||
|
||||
ps_alive=0
|
||||
pidfile="$(mysqld_get_param pid-file)"
|
||||
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" >/dev/null 2>&1; then
|
||||
if [ -f "$pidfile" ] && mysql_kill -0 2> /dev/null && \
|
||||
[ "$(readlink "/proc/$(cat "$pidfile")/exe")" = "$MYSQLD" ]; then
|
||||
ps_alive=1
|
||||
fi
|
||||
|
||||
if { [ "$1" = check_alive ] && [ $ping_alive = 1 ]; } || \
|
||||
{ [ "$1" = check_dead ] && [ $ping_alive = 0 ] \
|
||||
&& [ $ps_alive = 0 ]; }
|
||||
if { [ "$1" = check_alive ] && [ $ps_alive = 1 ]; } || \
|
||||
{ [ "$1" = check_dead ] && [ $ps_alive = 0 ]; }
|
||||
then
|
||||
return 0 # EXIT_SUCCESS
|
||||
else
|
||||
|
@ -58,25 +66,28 @@ mysqld_status() {
|
|||
fi
|
||||
}
|
||||
|
||||
start() {
|
||||
start_service() {
|
||||
conf=/etc/mysql/my.cnf
|
||||
logdir=/var/log/mysql
|
||||
rundir=/var/run/mysqld
|
||||
|
||||
hint="please fix your server configuration in /etc/mysql/"
|
||||
|
||||
for i in "$MYSQLD" "$MYSQLADMIN" "$MYSQLDSAFE"; do
|
||||
if [ ! -x "$i" ]; then
|
||||
$LOGGER "$i is missing"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -x "$MYSQLD" ]; then
|
||||
$LOGGER "$MYSQLD is missing"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -r "$conf" ]; then
|
||||
$LOGGER "$conf cannot be read"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if mysqld_status check_alive; then
|
||||
$LOGGER "server is already running"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
config_load "$NAME"
|
||||
|
||||
config_get_bool enabled general enabled 0
|
||||
|
@ -91,18 +102,6 @@ start() {
|
|||
datadir="$(mysqld_get_param datadir)"
|
||||
tmpdir="$(mysqld_get_param tmpdir)"
|
||||
|
||||
if [ -z "$datadir" ]; then
|
||||
$LOGGER "datadir is not set"
|
||||
$LOGGER "$hint"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$tmpdir" ]; then
|
||||
$LOGGER "tmpdir is not set"
|
||||
$LOGGER "$hint"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$datadir/mysql/tables_priv.MAD" ]; then
|
||||
args="--force"
|
||||
basedir="$(mysqld_get_param basedir)"
|
||||
|
@ -111,41 +110,39 @@ start() {
|
|||
$LOGGER "Cannot detect privileges table. You might need to run"
|
||||
$LOGGER "'mysql_install_db \"$args\"'"
|
||||
$LOGGER "to initialize the system tables."
|
||||
$LOGGER "Then hand it ower to MariaDB user"
|
||||
$LOGGER "'chown -Rh \"$my_user:$my_group\" \"$datadir\"'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Start daemon
|
||||
if mysqld_status check_alive; then
|
||||
$LOGGER "server is already running"
|
||||
else
|
||||
for i in "$logdir" "$rundir"; do
|
||||
opts="-m 0750"
|
||||
if ! [ -e "$i" ]; then
|
||||
# $rundir needs to be accessible for
|
||||
# clients
|
||||
if [ "$i" = "$rundir" ]; then
|
||||
opts=
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
mkdir -p $opts "$i"
|
||||
[ -d "$i" ] && chown mariadb:mariadb "$i"
|
||||
for i in "$logdir" "$rundir" "$tmpdir" "$datadir"; do
|
||||
opts="-m 0750"
|
||||
if ! [ -e "$i" ]; then
|
||||
# $rundir needs to be accessible for
|
||||
# clients
|
||||
if [ "$i" = "$rundir" ]; then
|
||||
opts=
|
||||
fi
|
||||
done
|
||||
# shellcheck disable=SC2154,SC2086
|
||||
"$MYSQLDSAFE" $options >/dev/null 2>&1 &
|
||||
fi
|
||||
}
|
||||
# shellcheck disable=SC2086
|
||||
mkdir -p $opts "$i"
|
||||
[ -d "$i" ] && chown -Rh "$my_user:$my_group" "$i"
|
||||
fi
|
||||
done
|
||||
|
||||
stop() {
|
||||
if ! mysqld_status check_dead; then
|
||||
"$MYSQLADMIN" shutdown
|
||||
fi
|
||||
}
|
||||
# Start daemon
|
||||
procd_open_instance
|
||||
|
||||
reload() {
|
||||
if mysqld_status check_alive; then
|
||||
"$MYSQLADMIN" reload
|
||||
else
|
||||
$LOGGER "server is not running"
|
||||
fi
|
||||
# shellcheck disable=SC2154 disable=SC2086
|
||||
procd_set_param command "$MYSQLD" $options
|
||||
procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
|
||||
# run as user
|
||||
procd_set_param user "$my_user"
|
||||
# forward stderr to logd
|
||||
procd_set_param stderr 1
|
||||
# use HUP to reload
|
||||
procd_set_param reload_signal HUP
|
||||
# terminate using signals
|
||||
procd_set_param term_timeout 60
|
||||
|
||||
procd_close_instance
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue