WL#10441: Add mysqld_safe-functionality to server

Affects: Server-8.0   —   Status: Complete

Re-implement parts of the logic currently found in the mysqld_safe script inside the server. Including

  • find the full path to executable
  • find basedir (mysql_home) from this
  • set sharedir and messages dir
  • provide short-cuts for the --initialize and --daemonize options
  • improve usage of error log during startup
  • improve feedback given to users when starting as a daemon (to facilitate integration into the various service management systems)

BUG#75343 is fixed by this worklog.

User Documentation

Functional Requirements

FR-1
Find the full path to executable from argv[0]
FR-2
Find basedir (mysql_home) from expanded executable path
FR-3
Set sharedir and messages dir based on found basedir
FR-4
Support all packages, make install and sandbox run
FR-5
-I shortcut for --initialize
FR-6
-D shortcut for --daemonize
FR-7
Change the default for --log-error to "" when running with --daemonize and not connected to tty
FR-8
Ensure that error log output is not lost if error log cannot be redirected
FR-9
Inform user about pid and error log location when appropriate
FR-10
(Stretch) Identify and remove CMAKE constants made redundant when resolving basedir at runtime

Non-Functional Requirements

NFR-1
Existing scripts and setups must continue to work
NFR-2
Changes should attempt to feel "intuitive" for the user
  • -I and -D will become aliases for --initialize and --daemonize
  • The name of the error log file and the pid file will be printed to stdout whenever connected to a tty
  • Error log messages are dumped to stderr if we fail to open the chosen file
  • Add shortcuts to the system variable/option description for --daemonize and --initialize.
  • Change the existing test which aborts when running with --daemonize and --log-error is unset and not connected to tty, so that it sets log_error_dest to "" and continues, rather than aborts.
  • Use my_access() to ensure that we are actually able to write to the error log before redirecting. This allows user to see error log messages on stderr if the chosen file cannot be written to.
  • Clean up error reporting in mysqld::runtime::mysqld_daemonize() to make it easier to diagnose problems. Always print name of error log and pidfile when running with --daemonize and connected to tty.
  • Find the full path to the server executable. Do this by
    • If it is already a full path, use it as is
    • If it is a relative path (at least one directory, possibly . or ..) look it up using my_realpath()
    • If it is a bare name, look it up in PATH
  • Use the full path to the excutable to obtain the
    • bindir as the dir part of the executable path
    • basedir (aka mysql_home) as $bindir/..