supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* Warning about mysqld's behaviour
@ 2005-04-11  3:16 Charlie Brady
  2005-04-14  8:53 ` Gerrit Pape
  0 siblings, 1 reply; 5+ messages in thread
From: Charlie Brady @ 2005-04-11  3:16 UTC (permalink / raw)



Version of mysql is 3.23.58. I haven't looked at other versions, so don't 
know whether this is new or old brain-damage.

I have a straightforward run file:

#!/bin/sh
exec /usr/libexec/mysqld \
  --defaults-file=/etc/my.cnf \
  --basedir=/usr \
  --datadir=/var/lib/mysql \
  --user=mysql \
  --pid-file=/var/run/mysqld/mysqld.pid

This starts a set of four mysqld processes/threads:

...
   492 ?        S      0:00  \_ supervise mysqld
31796 ?        S      0:00  |   \_ /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --
31797 ?        S      0:00  |       \_ /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysq
31798 ?        S      0:00  |           \_ /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/
31800 ?        S      0:00  |           \_ /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/
493   ?        S      0:00  \_ supervise log
...

But notice that the pid file doesn't reference the parent process:

sh-2.05a# svstat .
.: up (pid 31796) 123 seconds, normally down
sh-2.05a#

sh-2.05a# cat /var/run/mysqld/mysqld.pid ; echo
31798
sh-2.05a#

But, it's worse than that, Jim! The parent process - the one that 
supervise is watching and "controlling" ignores INT, TERM and QUIT 
signals.

sh-2.05a# kill -TERM 31796
sh-2.05a# svstat .
.: up (pid 31796) 309 seconds, normally down
sh-2.05a# kill -QUIT 31796
sh-2.05a# svstat .
.: up (pid 31796) 321 seconds, normally down
sh-2.05a# kill -INT 31796
sh-2.05a# svstat .
.: up (pid 31796) 327 seconds, normally down
sh-2.05a#

So we lose control of the daemon:

sh-2.05a# svc -t .
sh-2.05a# svstat .
.: up (pid 31796) 417 seconds, normally down
sh-2.05a#

Fortunately runit provides an easy solution to this problem (although we 
are left with no option but to trust a pid file, with all the problems 
that entails). We just create control/t and control/d files (at least), 
containing:

#! /bin/sh
exec kill -TERM $(cat /var/run/mysqld/mysqld.pid)

Without this feature from runit, we need to do something like this to run 
mysqld under supervise:

trap 'read pid </var/run/mysqld/mysqld.pid && kill "$pid"' TERM QUIT || exit "$?"
/usr/libexec/mysqld .... --pid-file=/var/run/mysqld/mysqld.pid &
wait

[Gerrit, if you can verify this, you'll need to update your run script 
list.]

---
Charlie


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-04-14 18:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-11  3:16 Warning about mysqld's behaviour Charlie Brady
2005-04-14  8:53 ` Gerrit Pape
2005-04-14 12:07   ` Alex Efros
2005-04-14 15:29     ` Charlie Brady
2005-04-14 18:05   ` Vincent Danen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).