fantasyni / mysql-master-ha

Automatically exported from code.google.com/p/mysql-master-ha
0 stars 0 forks source link

wrong exit code logic in failover_start script example? #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The example code on 

  http://code.google.com/p/mysql-master-ha/wiki/Using_With_Clustering_Software

currently reads:

  rc=`masterha_master_switch --master_state=dead --interactive=0 --wait_on_failover_error=0 --dead_master_host=host1 --new_master_host=host2`
  exit $rc

The `` operator actually doesn't return the exit code of the enclosed command 
but its stdout output. As long as the output is actually empty the code above 
works as expected, returning the exit status of the executed code as "exit $rc" 
effectively becomes just "exit" and so returns the exit status of the previous 
command. 

As soon as the command in backticks actually returns text the result will 
become this instead though:

  bash: exit: some_text: numeric argument required

and the actual exit status will always be "2" for "incorrect use of builtin 
shell argument" even if the actual code in backticks executed successfully

So the right code should actually be just

  start)
  `...`
  exit

to return the exit status, or maybe using "exit $?" instead of just "exit" 
to make it more explicit. The rc=... assignment on the other hand can be 
removed completely

Or am i missing something in the original code?

Original issue reported on code.google.com by hartmut....@gmail.com on 19 Apr 2012 at 12:45

GoogleCodeExporter commented 9 years ago
Thanks. This was a documentation bug. Fixed!

Original comment by Yoshinor...@gmail.com on 19 Apr 2012 at 2:37