mariadb: Use procd and run as user

Drop mysqld_safe and use procd instead. Also run as a user.

Signed-off-by: Michal Hrusecky <michal.hrusecky@turris.com>
This commit is contained in:
Michal Hrusecky 2020-10-13 08:52:42 +02:00
parent a01637ddf0
commit 595f0f1a2d
No known key found for this signature in database
GPG key ID: 7B7562FE6F4D91EF

View file

@ -5,14 +5,17 @@
START=95 START=95
# shellcheck disable=SC2034 # shellcheck disable=SC2034
STOP=10 STOP=10
# shellcheck disable=SC2034
USE_PROCD=1
NAME=mysqld NAME=mysqld
my_user="mariadb"
my_group="mariadb"
LOGGER="/usr/bin/logger -p user.err -s -t $NAME --" LOGGER="/usr/bin/logger -p user.err -s -t $NAME --"
[ -x "$LOGGER" ] || LOGGER="echo" [ -x "$LOGGER" ] || LOGGER="echo"
MYSQLD="/usr/bin/$NAME" MYSQLD="/usr/bin/$NAME"
MYSQLDSAFE="/usr/bin/mysqld_safe"
pidfile="" pidfile=""
@ -63,25 +66,28 @@ mysqld_status() {
fi fi
} }
start() { start_service() {
conf=/etc/mysql/my.cnf conf=/etc/mysql/my.cnf
logdir=/var/log/mysql logdir=/var/log/mysql
rundir=/var/run/mysqld rundir=/var/run/mysqld
hint="please fix your server configuration in /etc/mysql/" hint="please fix your server configuration in /etc/mysql/"
for i in "$MYSQLD" "$MYSQLDSAFE"; do if [ ! -x "$MYSQLD" ]; then
if [ ! -x "$i" ]; then $LOGGER "$MYSQLD is missing"
$LOGGER "$i is missing"
exit 1 exit 1
fi fi
done
if [ ! -r "$conf" ]; then if [ ! -r "$conf" ]; then
$LOGGER "$conf cannot be read" $LOGGER "$conf cannot be read"
exit 1 exit 1
fi fi
if mysqld_status check_alive; then
$LOGGER "server is already running"
exit 0
fi
config_load "$NAME" config_load "$NAME"
config_get_bool enabled general enabled 0 config_get_bool enabled general enabled 0
@ -116,14 +122,12 @@ start() {
$LOGGER "Cannot detect privileges table. You might need to run" $LOGGER "Cannot detect privileges table. You might need to run"
$LOGGER "'mysql_install_db \"$args\"'" $LOGGER "'mysql_install_db \"$args\"'"
$LOGGER "to initialize the system tables." $LOGGER "to initialize the system tables."
$LOGGER "Then hand it ower to MariaDB user"
$LOGGER "'chown -Rh \"$my_user:$my_group\" \"$datadir\"'"
exit 1 exit 1
fi fi
# Start daemon for i in "$logdir" "$rundir" "$tmpdir" "$datadir"; do
if mysqld_status check_alive; then
$LOGGER "server is already running"
else
for i in "$logdir" "$rundir"; do
opts="-m 0750" opts="-m 0750"
if ! [ -e "$i" ]; then if ! [ -e "$i" ]; then
# $rundir needs to be accessible for # $rundir needs to be accessible for
@ -133,31 +137,24 @@ start() {
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
mkdir -p $opts "$i" mkdir -p $opts "$i"
[ -d "$i" ] && chown mariadb:mariadb "$i" [ -d "$i" ] && chown -Rh "$my_user:$my_group" "$i"
fi fi
done done
# shellcheck disable=SC2154,SC2086
"$MYSQLDSAFE" $options >/dev/null 2>&1 &
fi
}
stop() { # Start daemon
timeout="0" procd_open_instance
while mysqld_status check_alive && [ "$timeout" -lt 60 ]; do
mysql_kill -TERM
sleep 1
timeout="$(($timeout + 1))"
done
if ! mysqld_status check_dead; then
$LOGGER "server is failing to stop"
mysql_kill -KILL
fi
}
reload() { # shellcheck disable=SC2086
if mysqld_status check_alive; then procd_set_param command "$MYSQLD" $options
mysql_kill -HUP procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
else # run as user
$LOGGER "server is not running" procd_set_param user "$my_user"
fi # 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
} }