WL#13705: add pid-file option

Affects: Server-8.0   —   Status: Complete


MySQL Router allows writing PID-files on startup only through setting the ROUTER_PID environment variable to a filename the pid-file shall be written to. (It is ignored if router is called with --bootstrap.)

Other server apps like MySQL Server use --pid-file to pass the location to store the PID file.


  • add a --pid-file commandline option to router.
  • add a pid_file config file option to router.
if --bootstrap is not specified, setting --pid-file on the commandline, pid_file configfile or ROUTER_PID on environment its value MUST be used as location for the pid-file.
--pid-file on commandline MUST take precedence over pid_file in the config-file.
pid_file in config-file MUST take precedence over ROUTER_PID on environment.
if the location of the pid-file is empty, no pid-file MUST be written
if the location of the pid-file is not absolute, its path is relative to runtime_folder config-variable.
if the location of the pid-file is NOT empty and the pid-file does not exist, a numeric PID MUST be written to the specified location

Failure Scenarios

If --bootstrap is not specified:

if the pid-file already exists, router MUST fail
if pid_file is set, but empty, router MUST fail
if ROUTER_PID is set, but empty, router MUST fail
if --pid-file is set, but empty, router MUST fail
if writing the PID file fails, router MUST fail

If --bootstrap is specified:

if --pid-file is specified, router MUST fail.

Non-failure Scenarios

If --bootstrap is specified:

ROUTER_PID env-var and pid_file config-option MUST be ignored.

Commandline option

mysqlrouter --pid-file=<filename>

Configuration file


Note on current behaviour

At present, MySQL Router only writes the PID-file if ROUTER_PID environment is set. By default, it will not create the PID-file. After this WL, this default behaviour should be extended to create a PID-file only if at least one of the {ROUTER_PID env var, --pid-file cmdline option, pid_file config option} is provided.

Also, PID-file will be written only when Router runs in its "regular" (not bootstrap) mode. Bootstrap mode never writes a PID-file.