From a4df7b1db330f57421459309a2d91fc46ebb388f Mon Sep 17 00:00:00 2001 From: Sebastian Kemper Date: Sat, 30 Jun 2018 20:05:25 +0200 Subject: [PATCH] mariadb: convert init script to procd - also adds mariadb user to run the server as - tweaks the default configuration a bit Signed-off-by: Sebastian Kemper --- utils/mariadb/Makefile | 9 ++++-- utils/mariadb/conf/my.cnf | 16 +++++------ utils/mariadb/conf/mysqld.default | 10 +++++++ utils/mariadb/files/mysqld.init | 47 ++++++++++++++++++++++--------- 4 files changed, 59 insertions(+), 23 deletions(-) create mode 100644 utils/mariadb/conf/mysqld.default diff --git a/utils/mariadb/Makefile b/utils/mariadb/Makefile index 98dde04ac6..92cadf31b8 100644 --- a/utils/mariadb/Makefile +++ b/utils/mariadb/Makefile @@ -268,6 +268,7 @@ define Package/mariadb-server TITLE:=MariaDB database core server binaries MENU:=1 PROVIDES:=mysql-server + USERID:=mariadb=376:mariadb=376 endef define Package/mariadb-server/description @@ -344,9 +345,10 @@ CMAKE_OPTIONS += \ -DINSTALL_SCRIPTDIR=bin \ -DINSTALL_SQLBENCHDIR="" \ -DINSTALL_SUPPORTFILESDIR=share/mysql \ - -DMYSQLD_USER=root \ + -DINSTALL_UNIX_ADDRDIR=/var/run/mysqld/mysqld.sock \ + -DMYSQLD_USER=mariadb \ -DMYSQL_DATADIR=/var/lib/mysql \ - -DMYSQL_UNIX_ADDR=/var/run/mysqld.sock \ + -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \ -DSKIP_TESTS=ON \ -DWITH_ASAN=OFF \ -DWITH_EMBEDDED_SERVER=OFF \ @@ -463,10 +465,12 @@ endef define Package/mariadb-server/install $(INSTALL_DIR) $(1)/usr/bin $(foreach b,$(MARIADB_SERVER),$(call Package/mariadb/install/bin,$(1),$(b));) + $(INSTALL_DIR) $(1)/etc/default $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_DIR) $(1)/etc/mysql/conf.d $(INSTALL_BIN) files/mysqld.init $(1)/etc/init.d/mysqld $(INSTALL_CONF) conf/my.cnf $(1)/etc/mysql + $(INSTALL_CONF) conf/mysqld.default $(1)/etc/default/mysqld $(INSTALL_DIR) $(1)$(PLUGIN_DIR) $(INSTALL_CONF) $(PKG_INSTALL_DIR)$(PLUGIN_DIR)/daemon_example.ini $(1)$(PLUGIN_DIR) $(INSTALL_DIR) $(1)/usr/share/mysql/english @@ -484,6 +488,7 @@ define Package/mariadb-server-extra/install endef define Package/mariadb-server/conffiles +/etc/default/mysqld /etc/mysql/my.cnf $(PLUGIN_DIR)/daemon_example.ini endef diff --git a/utils/mariadb/conf/my.cnf b/utils/mariadb/conf/my.cnf index ec2ade2c89..effa88a771 100644 --- a/utils/mariadb/conf/my.cnf +++ b/utils/mariadb/conf/my.cnf @@ -1,10 +1,10 @@ [client] port = 3306 -socket = /var/run/mysqld.sock +socket = /var/run/mysqld/mysqld.sock [mysqld] -user = root -socket = /var/run/mysqld.sock +user = mariadb +socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr @@ -21,21 +21,21 @@ skip-external-locking bind-address = 127.0.0.1 # Fine Tuning -key_buffer = 16M +key_buffer_size = 16M max_allowed_packet = 16M thread_stack = 192K -thread_cache_size = 8 +thread_cache_size = 8 # Here you can see queries with especially long duration #log_slow_queries = /var/log/mysql/mysql-slow.log -#long_query_time = 2 +#long_query_time = 2 #log-queries-not-using-indexes # The following can be used as easy to replay backup logs or for replication. #server-id = 1 -#log_bin = /var/log/mysql/mysql-bin.log +#log_bin = /var/log/mysql/mysql-bin.log #expire_logs_days = 10 -#max_binlog_size = 100M +#max_binlog_size = 100M #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name diff --git a/utils/mariadb/conf/mysqld.default b/utils/mariadb/conf/mysqld.default new file mode 100644 index 0000000000..fe9c698ba5 --- /dev/null +++ b/utils/mariadb/conf/mysqld.default @@ -0,0 +1,10 @@ +# 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="" diff --git a/utils/mariadb/files/mysqld.init b/utils/mariadb/files/mysqld.init index fcd08d61ed..abc99fc7a9 100644 --- a/utils/mariadb/files/mysqld.init +++ b/utils/mariadb/files/mysqld.init @@ -1,32 +1,53 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2010-2011 OpenWrt.org +# Copyright (C) 2010-2018 OpenWrt.org START=95 STOP=10 -SERVICE_DAEMONIZE=1 -SERVICE_WRITE_PID=1 -SERVICE_STOP_TIME=9 -PROG='/usr/bin/mysqld' +USE_PROCD=1 -start() { +#PROCD_DEBUG=1 + +MYSQLD=mysqld + +DEFAULT=/etc/default/$MYSQLD +LOGGER="/usr/bin/logger -p user.err -s -t $MYSQLD" +PROG=/usr/bin/$MYSQLD + +unset MY_ARGS MY_GROUP MY_USER + +[ -f $DEFAULT ] && . $DEFAULT + +my_user="${MY_USER:-mariadb}" +my_group="${MY_GROUP:-mariadb}" + +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 -s "[ERROR] datadir '$datadir' in '$conf' does not exist" + $LOGGER "datadir '$datadir' in '$conf' does not exist" return 1 } [ -f "$datadir/mysql/tables_priv.MYD" ] || { - logger -s "[ERROR] can not detect privileges table, you might need to" - logger -s "run 'mysql_install_db --force' to initialize the system tables" + $LOGGER "cannot detect privileges table, you might need to" + $LOGGER "run 'mysql_install_db --force' to initialize the system tables" return 1 } - service_start "$PROG" -} + 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 + + procd_open_instance + + procd_set_param command $PROG $MY_ARGS + procd_set_param pidfile /var/run/mysqld.pid + # forward stderr to logd + procd_set_param stderr 1 -stop() { - service_stop "$PROG" + procd_close_instance } -- 2.30.2