You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2010-2018 OpenWrt.org
  3. START=95
  4. STOP=10
  5. USE_PROCD=1
  6. #PROCD_DEBUG=1
  7. NAME=mysqld
  8. LOGGER="/usr/bin/logger -p user.err -s -t $NAME"
  9. COMMAND=/usr/bin/$NAME
  10. mysqld_get_param() {
  11. $COMMAND --print-defaults \
  12. | tr " " "\n" \
  13. | grep -- "--$1" \
  14. | tail -n 1 \
  15. | cut -d= -f2
  16. }
  17. start_service() {
  18. local conf=/etc/mysql/my.cnf
  19. local dir
  20. local user=mariadb
  21. local datadir
  22. local logdir=/var/log/mysql
  23. local rundir=/var/run/mysqld
  24. local tmpdir
  25. local enabled
  26. local log_stderr
  27. local log_stdout
  28. local options
  29. if [ ! -x $COMMAND ]; then
  30. $LOGGER $COMMAND is missing
  31. exit 1
  32. fi
  33. if [ ! -r $conf ]; then
  34. $LOGGER $conf cannot be read
  35. exit 1
  36. fi
  37. config_load $NAME
  38. config_get_bool enabled general enabled 0
  39. if [ $enabled -eq 0 ]; then
  40. $LOGGER service not enabled in /etc/config/$NAME
  41. exit 1
  42. fi
  43. config_get_bool log_stderr general log_stderr 1
  44. config_get_bool log_stdout general log_stdout 1
  45. config_get options general options
  46. datadir=$(mysqld_get_param datadir)
  47. tmpdir=$(mysqld_get_param tmpdir)
  48. if [ -z "$datadir" ]; then
  49. $LOGGER datadir is not set
  50. exit 1
  51. fi
  52. if [ -z "$tmpdir" ]; then
  53. $LOGGER tmpdir is not set.
  54. exit 1
  55. fi
  56. [ -e "$datadir" ] || mkdir -p "$datadir"
  57. for dir in "$logdir" "$rundir" "$tmpdir"; do
  58. if [ ! -e "$dir" ]; then
  59. mkdir -p "$dir"
  60. chown $user "$dir"
  61. fi
  62. done
  63. if [ ! -f "$datadir/mysql/tables_priv.MYD" ]; then
  64. $LOGGER "cannot detect privileges table, you might need to"
  65. $LOGGER "run 'mysql_install_db --force' to initialize the system tables"
  66. exit 1
  67. fi
  68. procd_open_instance
  69. procd_set_param command $COMMAND $options
  70. # forward stderr to logd
  71. procd_set_param stderr $log_stderr
  72. # same for stdout
  73. procd_set_param stdout $log_stdout
  74. procd_close_instance
  75. }