Strange or obsolete code in mysql initscript

Bug #359177 reported by Alexey Sveshnikov
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
mysql-dfsg-5.0 (Ubuntu)
Confirmed
Low
Patch for MySQL team

Bug Description

Hi.

There is several snippets in mysql init script, with 'log_end_msg 1', call and some code after it.

'log_end_msg' returns it's argument as exit status. So 'log_end_msg 1' will be intrepreted by bash as command that always fails. Option '-e' in bash causes script to bail out in case of any error.

So in this fragment:

    'stop')
          .....
          log_daemon_msg "Stopping MySQL database server" "mysqld"
          if ! mysqld_status check_dead nowarn; then
            set +e
            shutdown_out=`$MYADMIN shutdown 2>&1`; r=$?
            set -e
            if [ "$r" -ne 0 ]; then
              log_end_msg 1

All futher code will never being executed:

              [ "$VERBOSE" != "no" ] && log_failure_msg "Error: $shutdown_out"
              log_daemon_msg "Killing MySQL database server by signal" "mysqld"
              killall -15 mysqld
  ...

Moreover, 'VERBOSE' variable is undefined.

So, I think this code is a little strange one. By the way, I also think that killing all mysqld processes is not very good idea too (MySQL Enterprise Monitor, for example, runs it's own mysqld instance that shouldn't be killed by this init script)

I can send a patch for it if it will be helpful.

Revision history for this message
Andreas Olsson (andol) wrote :

I believe I can confirm this. Unless I'm thinking entirely wrong there is no way that code after "log_end_msg 1" will be executed.

Changed in mysql-dfsg-5.0 (Ubuntu):
status: New → Confirmed
Andreas Olsson (andol)
Changed in mysql-dfsg-5.0 (Ubuntu):
importance: Undecided → Low
Revision history for this message
born2chill (david-gabriel) wrote :

I also have problems with this initscript (mostly with wrong return codes in scripted shutdowns), however i think that the author overlooked an 'else' statement:

@142ff: instead of:
142 if [ "$r" -ne 0 ]; then
143 log_end_msg 1
144 [ "$VERBOSE" != "no" ] && log_failure_msg "Error: $shutdown_out"
145 log_daemon_msg "Killing MySQL database server by signal" "mysqld"
146 killall -15 mysqld
147 server_down=
148 for i in 1 2 3 4 5 6 7 8 9 10; do
149 sleep 1
150 if mysqld_status check_dead nowarn; then server_down=1; break; fi
151 done

imho it probably shoud be:
142 if [ "$r" -ne 0 ]; then
143 log_end_msg 1
144 [ "$VERBOSE" != "no" ] && log_failure_msg "Error: $shutdown_out"
145 log_daemon_msg "Killing MySQL database server by signal" "mysqld"
146 killall -15 `pgrep mysqld_safe\ --server-id=${INSTANCENMB}`
147 else
148 server_down=
149 for i in `seq 1 10`; do
150 sleep 1
151 if mysqld_status check_dead nowarn; then server_down=1; break; fi
152 done

in this case the server is only killed if the 'mysqladmin shutdown' before the statement fails, otherwise the script goes into the 10 seconds for-loop checking if mysql has gone away for sure, otherwise killing it with -9. It is still true that the 'VERBOSE'-test is obsolete...

br,
David

Revision history for this message
Chuck Short (zulcss) wrote :

If you can submit this as a patch that would be great.
Thanks
chuck

Revision history for this message
born2chill (david-gabriel) wrote :

Patch for the mysql init script attached. Reworked the 'stop'-section some more, removed unused / old variables etc...

br,
David

Revision history for this message
Alexey Sveshnikov (mahoro) wrote :

Hi, David.

I think it's a bad idea to kill MySQL with -9 signal.
It's o.k. for MySQL instances with big key_buffer_size to stop within several minutes.
IMHO, it's better just to print that MySQL can't be stopped ant let user to decide what to do with it.

Revision history for this message
born2chill (david-gabriel) wrote :

Hi Alexey,

true, killing all mysqld-procs isn't the best choice, however i tried to stick to the original initscript which also killed the processes after some time. Its no problem to change this behaviour if wanted, only the 'kill -9' and 'log_msg' lines have to be altered. Who is up to decide/implement this (sorry, i don't know any mysql-maintainer...)?

br,
David

Changed in mysql-dfsg-5.0 (Ubuntu):
assignee: nobody → Patch for MySQL team (mysql-patch-team)
Revision history for this message
Alexey Sveshnikov (mahoro) wrote :

Hi again.

The original point of this bug is that initscript have code for killing MySQL but this code is disabled in rather strange way (by putting log_end_msg 1, see the first post). I think this code should be disabled in more obvioius way or removed at all.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.