Browse Source

mariadb: update init script to use uci

Does away with /etc/default/mysqld, introduces uci configuration
instead. The init script receives some further brushing up, like a
function (copied from Debian) to get mysqld configuration parameters
easily and quickly.

Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
lilik-openwrt-22.03
Sebastian Kemper 6 years ago
parent
commit
2de1c6c05f
4 changed files with 89 additions and 44 deletions
  1. +4
    -4
      utils/mariadb/Makefile
  2. +0
    -10
      utils/mariadb/conf/mysqld.default
  3. +7
    -0
      utils/mariadb/files/mysqld.config
  4. +78
    -30
      utils/mariadb/files/mysqld.init

+ 4
- 4
utils/mariadb/Makefile View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=mariadb
PKG_VERSION:=10.2.19
PKG_RELEASE:=2
PKG_RELEASE:=3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL := \
@ -332,7 +332,7 @@ endef
define Package/mariadb-server-base/conffiles
$(CONF_DIR)/conf.d/50-server.cnf
$(CONF_DIR)/conf.d/60-galera.cnf
/etc/default/mysqld
/etc/config/mysqld
endef
define Package/mariadb-server-base/description
@ -554,13 +554,13 @@ define Package/mariadb-server-base/install
$(INSTALL_DIR) $(1)$(CONF_DIR)/conf.d
$(INSTALL_DIR) $(1)$(SHARE_DIR)/charsets
$(INSTALL_DIR) $(1)$(SHARE_DIR)/english
$(INSTALL_DIR) $(1)/etc/default
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) files/mysqld.init $(1)/etc/init.d/mysqld
$(SED) '/^[a-z]/s/^/#/' $(PKG_INSTALL_DIR)$(SHARE_DIR)/wsrep.cnf
$(INSTALL_CONF) $(PKG_INSTALL_DIR)$(SHARE_DIR)/wsrep.cnf $(1)$(CONF_DIR)/conf.d/60-galera.cnf
$(INSTALL_CONF) conf/50-server.cnf $(1)$(CONF_DIR)/conf.d
$(INSTALL_CONF) conf/mysqld.default $(1)/etc/default/mysqld
$(INSTALL_CONF) files/mysqld.config $(1)/etc/config/mysqld
$(INSTALL_DATA) $(PKG_INSTALL_DIR)$(SHARE_DIR)/charsets/* $(1)$(SHARE_DIR)/charsets
$(INSTALL_DATA) $(PKG_INSTALL_DIR)$(SHARE_DIR)/english/errmsg.sys $(1)$(SHARE_DIR)/english
$(INSTALL_DATA) $(PKG_INSTALL_DIR)$(SHARE_DIR)/fill_help_tables.sql $(1)$(SHARE_DIR)


+ 0
- 10
utils/mariadb/conf/mysqld.default View File

@ -1,10 +0,0 @@
# The user and group that will run the MySQL server. The user mariadb is
# automatically created by the mariadb-server package, hence that is the
# default choice.
#MY_USER=mariadb
#MY_GROUP=mariadb
# Additional arguments you want to pass to the MySQL server.
#MY_ARGS=""

+ 7
- 0
utils/mariadb/files/mysqld.config View File

@ -0,0 +1,7 @@
config mysqld 'general'
option enabled '0'
option log_stderr '1'
option log_stdout '1'
option options ''

+ 78
- 30
utils/mariadb/files/mysqld.init View File

@ -8,46 +8,94 @@ USE_PROCD=1
#PROCD_DEBUG=1
MYSQLD=mysqld
NAME=mysqld
DEFAULT=/etc/default/$MYSQLD
LOGGER="/usr/bin/logger -p user.err -s -t $MYSQLD"
PROG=/usr/bin/$MYSQLD
LOGGER="/usr/bin/logger -p user.err -s -t $NAME"
COMMAND=/usr/bin/$NAME
unset MY_ARGS MY_GROUP MY_USER
[ -f $DEFAULT ] && . $DEFAULT
my_user="${MY_USER:-mariadb}"
my_group="${MY_GROUP:-mariadb}"
mysqld_get_param() {
$COMMAND --print-defaults \
| tr " " "\n" \
| grep -- "--$1" \
| tail -n 1 \
| cut -d= -f2
}
start_service() {
local conf='/etc/mysql/my.cnf'
local datadir="$( sed -nE "s/^\s*datadir\s*=\s*('([^']*)'|\x22([^\x22]*)\x22|(.*\S))\s*$/\2\3\4/p" "$conf" )"
[ -d "$datadir" ] || {
$LOGGER "datadir '$datadir' in '$conf' does not exist"
return 1
}
[ -f "$datadir/mysql/tables_priv.MYD" ] || {
local conf=/etc/mysql/my.cnf
local dir
local user=mariadb
local datadir
local logdir=/var/log/mysql
local rundir=/var/run/mysqld
local tmpdir
local enabled
local log_stderr
local log_stdout
local options
if [ ! -x $COMMAND ]; then
$LOGGER $COMMAND is missing
exit 1
fi
if [ ! -r $conf ]; then
$LOGGER $conf cannot be read
exit 1
fi
config_load $NAME
config_get_bool enabled general enabled 0
if [ $enabled -eq 0 ]; then
$LOGGER service not enabled in /etc/config/$NAME
exit 1
fi
config_get_bool log_stderr general log_stderr 1
config_get_bool log_stdout general log_stdout 1
config_get options general options
datadir=$(mysqld_get_param datadir)
tmpdir=$(mysqld_get_param tmpdir)
if [ -z "$datadir" ]; then
$LOGGER datadir is not set
exit 1
fi
if [ -z "$tmpdir" ]; then
$LOGGER tmpdir is not set.
exit 1
fi
[ -e "$datadir" ] || mkdir -p "$datadir"
for dir in "$logdir" "$rundir" "$tmpdir"; do
if [ ! -e "$dir" ]; then
mkdir -p "$dir"
chown $user "$dir"
fi
done
if [ ! -f "$datadir/mysql/tables_priv.MYD" ]; then
$LOGGER "cannot detect privileges table, you might need to"
$LOGGER "run 'mysql_install_db --force' to initialize the system tables"
return 1
}
mkdir -p /var/lib/mysql
chown "$my_user":"$my_group" /var/lib/mysql
mkdir -p /var/run/mysqld
chown "$my_user":"$my_group" /var/run/mysqld
exit 1
fi
procd_open_instance
procd_set_param command $PROG $MY_ARGS
procd_set_param pidfile /var/run/mysqld.pid
procd_set_param command $COMMAND $options
# forward stderr to logd
procd_set_param stderr 1
procd_set_param stderr $log_stderr
# same for stdout
procd_set_param stdout $log_stdout
procd_close_instance
}

Loading…
Cancel
Save