目の前に僕らの道がある

勉強会とか、技術的にはまったことのメモ

MySQLがkillされてくれなくてつらい。。

ある意味ネタです。

こんな環境です。

[ LAB ] 16:30:25 masasuzu@labos%  lsb_release -a
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.3 LTS
Release:        12.04
Codename:       precise

いくらmysqldをkill -9しても死んでくれません!!

[ LAB ] 16:33:25 masasuzu@labos% ps -fe | egrep '[m]ysql'
mysql    15003     1  0 16:15 ?        00:00:02 /usr/sbin/mysqld
[ LAB ] 16:34:10 masasuzu@labos% sudo kill -9 15003
[ LAB ] 16:34:22 masasuzu@labos% ps -fe | egrep '[m]ysql'
mysql    28400     1 25 16:34 ?        00:00:00 /usr/sbin/mysqld
[ LAB ] 16:34:23 masasuzu@labos% sudo kill -9 28400
[ LAB ] 16:34:30 masasuzu@labos% ps -fe | egrep '[m]ysql'
mysql    28675     1  9 16:34 ?        00:00:00 /usr/sbin/mysqld

エラーログを見る限り、なんか勝手に立ち上がってる怖い。。

131017 16:34:22 [Note] Plugin 'FEDERATED' is disabled.
131017 16:34:22 InnoDB: The InnoDB memory heap is disabled
131017 16:34:22 InnoDB: Mutexes and rw_locks use GCC atomic builtins
131017 16:34:22 InnoDB: Compressed tables use zlib 1.2.3.4
131017 16:34:22 InnoDB: Initializing buffer pool, size = 400.0M
131017 16:34:22 InnoDB: Completed initialization of buffer pool
131017 16:34:22 InnoDB: highest supported file format is Barracuda.
131017 16:34:25  InnoDB: Waiting for the background threads to start
131017 16:34:26 InnoDB: 5.5.32 started; log sequence number 1485417561
131017 16:34:26 [Note] Recovering after a crash using 35705-bin
131017 16:34:26 [Note] Starting crash recovery...
131017 16:34:26 [Note] Crash recovery finished.
131017 16:34:26 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
131017 16:34:26 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
131017 16:34:26 [Note] Server socket created on IP: '0.0.0.0'.
131017 16:34:26 [Note] Event Scheduler: Loaded 0 events
131017 16:34:26 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.32-0ubuntu0.12.04.1-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)

131017 16:34:30 [Note] Plugin 'FEDERATED' is disabled.
131017 16:34:30 InnoDB: The InnoDB memory heap is disabled
131017 16:34:30 InnoDB: Mutexes and rw_locks use GCC atomic builtins
131017 16:34:30 InnoDB: Compressed tables use zlib 1.2.3.4
131017 16:34:30 InnoDB: Initializing buffer pool, size = 400.0M
131017 16:34:30 InnoDB: Completed initialization of buffer pool
131017 16:34:30 InnoDB: highest supported file format is Barracuda.
131017 16:34:32  InnoDB: Waiting for the background threads to start
131017 16:34:33 InnoDB: 5.5.32 started; log sequence number 1485417561
131017 16:34:33 [Note] Recovering after a crash using 35705-bin
131017 16:34:33 [Note] Starting crash recovery...
131017 16:34:33 [Note] Crash recovery finished.
131017 16:34:33 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
131017 16:34:33 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
131017 16:34:33 [Note] Server socket created on IP: '0.0.0.0'.
131017 16:34:33 [Note] Event Scheduler: Loaded 0 events
131017 16:34:33 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.32-0ubuntu0.12.04.1-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)

…。




結論から言うと、このMySQLupstartdaemon管理されていて、設定ファイルにrespawnを書いておくと、死んでも自動的に起動してくれるようです。
daemontoolsみたいですね。
ちなみに、aptでインストールしたときに勝手に設定されます。

% cat /etc/init/mysql.conf

# MySQL Service

description     "MySQL Server"
author          "Mario Limonciello <superm1@ubuntu.com>"

start on runlevel [2345]
stop on starting rc RUNLEVEL=[016]

respawn                          #<===== これ
respawn limit 2 5

env HOME=/etc/mysql
umask 007

# The default of 5 seconds is too low for mysql which needs to flush buffers
kill timeout 300

pre-start script
    #Sanity checks
    [ -r $HOME/my.cnf ]
    [ -d /var/run/mysqld ] || install -m 755 -o mysql -g root -d /var/run/mysqld
    /lib/init/apparmor-profile-load usr.sbin.mysqld
    LC_ALL=C BLOCKSIZE= df --portability /var/lib/mysql/. | tail -n 1 | awk '{ exit ($4<4096) }'
end script

exec /usr/sbin/mysqld

post-start script
   for i in `seq 1 30` ; do
        /usr/bin/mysqladmin --defaults-file="${HOME}"/debian.cnf ping && {
            exec "${HOME}"/debian-start
            # should not reach this line
            exit 2
        }
        statusnow=`status`
        if echo $statusnow | grep -q 'stop/' ; then
            exit 0
        elif echo $statusnow | grep -q 'respawn/' ; then
            exit 1
        fi
        sleep 1
    done
    exit 1
end script


からくりがこれで分かったので、kill -9しても死んでくれないと これで悩むことはないですね!!

…。まー普通は、MySQLに対してkill -9なんでしませんけど。