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,48 +122,39 @@ 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 opts="-m 0750"
$LOGGER "server is already running" if ! [ -e "$i" ]; then
else # $rundir needs to be accessible for
for i in "$logdir" "$rundir"; do # clients
opts="-m 0750" if [ "$i" = "$rundir" ]; then
if ! [ -e "$i" ]; then opts=
# $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"
fi fi
done # shellcheck disable=SC2086
# shellcheck disable=SC2154,SC2086 mkdir -p $opts "$i"
"$MYSQLDSAFE" $options >/dev/null 2>&1 & [ -d "$i" ] && chown -Rh "$my_user:$my_group" "$i"
fi fi
}
stop() {
timeout="0"
while mysqld_status check_alive && [ "$timeout" -lt 60 ]; do
mysql_kill -TERM
sleep 1
timeout="$(($timeout + 1))"
done done
if ! mysqld_status check_dead; then
$LOGGER "server is failing to stop"
mysql_kill -KILL
fi
}
reload() { # Start daemon
if mysqld_status check_alive; then procd_open_instance
mysql_kill -HUP
else # shellcheck disable=SC2086
$LOGGER "server is not running" procd_set_param command "$MYSQLD" $options
fi 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
} }