mariadb: convert init script to procd
authorSebastian Kemper <sebastian_ml@gmx.net>
Thu, 28 Jun 2018 19:31:40 +0000 (21:31 +0200)
committerSebastian Kemper <sebastian_ml@gmx.net>
Thu, 28 Jun 2018 19:31:42 +0000 (21:31 +0200)
Also create a user "mariadb" and use it for running the server. And
add possibility to easily add command line args.

Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
utils/mariadb/Makefile
utils/mariadb/conf/my.cnf
utils/mariadb/conf/mysqld.default [new file with mode: 0644]
utils/mariadb/files/mysqld.init

index 7f30fbe2af19115fd3ce9b135d11efa1fd5860b6..439ec941f3f44a38ac9870c4306784e039dac45c 100644 (file)
@@ -265,6 +265,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
@@ -341,10 +342,10 @@ CMAKE_OPTIONS += \
        -DINSTALL_SCRIPTDIR=bin \
        -DINSTALL_SQLBENCHDIR="" \
        -DINSTALL_SUPPORTFILESDIR=share/mysql \
-       -DINSTALL_UNIX_ADDRDIR=/var/run/mysqld.sock \
-       -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 \
@@ -461,10 +462,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
@@ -482,6 +485,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
index ec2ade2c8952ee6678b3262de24e6d0d8421c02f..effa88a7717cc7d8b22efd655a4426ada33f5a1e 100644 (file)
@@ -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 (file)
index 0000000..fe9c698
--- /dev/null
@@ -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=""
index fcd08d61edea6c7dc7560214e43c6a491cb36001..abc99fc7a98bfa7c8775b7cc8ac47c4e973d0576 100644 (file)
@@ -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
 }