Bug #91241 mysqlrouter init script doesn't show syntax errors in config file
Submitted: 13 Jun 2018 15:35 Modified: 18 Jun 2018 10:49
Reporter: Andrii Ustymenko Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Router Severity:S3 (Non-critical)
Version:8.0.11 OS:CentOS (6)
Assigned to: CPU Architecture:x86
Tags: mysqlrouter

[13 Jun 2018 15:35] Andrii Ustymenko
Description:
If there are any syntax errors in mysqlrouter.conf initscript still says [OK] and service is not getting up.

Error message gets suppressed not showing neither on stderr nor in mysqlrouter.log

The reason is the next bash-construction in /etc/init.d/mysqlrouter

  daemon $exec --user=mysqlrouter -c /etc/mysqlrouter/mysqlrouter.conf >/dev/null 2>&1 &
  ret=$?

It is bad because:
1) Stdout and stderr got redirected to /dev/null
2) $? is always 0 because the background task has been spawned

How to repeat:
1) Install mysqlrouter from official repo on Centos 6

2) Put some syntax error in /etc/mysqlrouter/mysqlrouter.conf

For instance:
  [routing:simple_redirect-1]
  bind_port = 7002
  mode = read-write
  destinations = 172.19.120.230:3306

3) Star the mysqlrouter service:

  [#]/etc/init.d/mysqlrouter start
  Starting mysqlrouter:                                      [  OK  ]

Process is not running. If manually invoke the corresponding command the output will be:
  
  mysqlrouter --user=mysqlrouter -c /etc/mysqlrouter/mysqlrouter.conf
  Error: Configuration error: Invalid section key 'simple_redirect-1'.

Suggested fix:
I have made the sufficient patch for the initscript. It is not perfect, but resolves the problem. We wait for pid to appear in the pid-file in the proper way and redirect the output into log-file. Also not sure daemon() is needed:

--- /etc/init.d/mysqlrouter     2018-06-13 09:38:26.946690337 +0200
+++ /etc/init.d/mysqlrouter.patched     2018-06-13 17:17:51.745660463 +0200
@@ -43,6 +43,17 @@
 lockfile=/var/lock/subsys/$prog
 datadir=/var/lib/mysqlrouter
 
+wait_for_pid() {
+  router_pid=$1
+  for i in `seq 1 5`;
+  do
+    [ -f $pidfile ] && [ $router_pid -eq $(cat $pidfile) ] && return 0
+    sleep 1
+  done
+ 
+  return 1
+}
+
 start () {
     [ -d $piddir ] || [ -L $piddir ] || install -d -m 0750 -o mysqlrouter -g mysqlrouter ${piddir}
     [ -d $logdir ] || [ -L $logdir ] || install -d -m 0750 -o mysqlrouter -g mysqlrouter ${logdir}
@@ -50,7 +61,8 @@
     export ROUTER_PID=$pidfile
     [ -d $datadir ] || mkdir -p $datadir
     chown mysqlrouter:mysqlrouter $datadir
-    daemon $exec --user=mysqlrouter -c /etc/mysqlrouter/mysqlrouter.conf >/dev/null 2>&1 &
+    $exec --user=mysqlrouter -c /etc/mysqlrouter/mysqlrouter.conf >>$logfile 2>&1 &
+    wait_for_pid $!
     ret=$?
     if [ $ret -eq "0" ]; then
        action $"Starting $prog: " /bin/true
[18 Jun 2018 10:49] Bogdan Kecman
Verified as described. Thanks for your report

all best
Bogdan