Bug #77696 init script ("service mysql status") incorrectly reports server is stopped in 5%
Submitted: 12 Jul 2015 18:02 Modified: 28 Sep 2015 18:54
Reporter: John Whitlock Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S2 (Serious)
Version:5.6.25, 5.6.26 OS:Ubuntu
Assigned to: CPU Architecture:Any

[12 Jul 2015 18:02] John Whitlock
Description:
Calling "service mysql status" returns that the server is stopped 5% - 10% of the time, even when it is running.  This is because the detection method is counting the processes:

PSCOUNT=$(ps -ef | grep "/usr/sbin/mysqld" | wc -l)

When running, the count is at least 2 - 1 for the actual mysqld process, and 1 for the grep for that process.  However, the grep sometimes does not appear in the process list.  On a vagrant VM install of mysql-community-server 5.6.25-1ubuntu12.04, the PSCOUNT is 1 about 5% - 10% of the time

How to repeat:
Run this while mysql is running:

for i in {1..100}; do ps -ef | grep "/usr/sbin/mysqld" | wc -l; done

See that the count is usually 2, but sometimes 1.  In these cases, "service mysql status" would return that the service is stopped, "service mysql start" would fail because it is already running, and "service mysql stop" would fail because it thinks the service is already stopped.

Suggested fix:
Use this instead:

PSCOUNT=$(ps -ef | grep "/usr/sbin/mysqld" | grep -v "grep" | wc -l)

This will cause the PSCOUNT to be 1 when the service is running, and 0 when it is not.

Change other lines reading the count from:

if [ "${PSCOUNT}" -gt 1 ];

to 

if [ "${PSCOUNT}" -ge 1 ];
[12 Jul 2015 18:03] John Whitlock
/etc/init.d/mysql, with modified PSCOUNT

Attachment: mysql (application/octet-stream, text), 3.99 KiB.

[1 Sep 2015 10:02] MySQL Verification Team
Hello John,

Thank you for the report.
Observed this issue(but <1%) with 5.6.26 build on Ubuntu 12.04.5 LTS.

Thanks,
Umesh
[1 Sep 2015 10:03] MySQL Verification Team
// 5.6.26

ushastry@ubuntu1204:~/Downloads$ dpkg -l|grep mysql
ii  mysql-apt-config                            0.3.5-1ubuntu12.04                  Auto configuration for MySQL APT Repo.
ii  mysql-client                                5.6.26-1ubuntu12.04                 MySQL Client meta package depending on latest version
ii  mysql-common                                5.6.26-1ubuntu12.04                 MySQL Common
ii  mysql-community-client                      5.6.26-1ubuntu12.04                 MySQL Client
ii  mysql-community-server                      5.6.26-1ubuntu12.04                 MySQL Server
ii  mysql-connector-python                      2.0.4-1ubuntu12.04                  MySQL database driver written in Python
ii  mysql-server                                5.6.26-1ubuntu12.04                 MySQL Server meta package depending on latest version
ushastry@ubuntu1204:~/Downloads$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.5 LTS"
NAME="Ubuntu"
VERSION="12.04.5 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.5 LTS)"
VERSION_ID="12.04"

ushastry@ubuntu1204:~/Downloads$ for i in {1..50000}; do ps -ef | grep "/usr/sbin/mysqld" | wc -l; done >> /tmp/ll.log

ushastry@ubuntu1204:~/Downloads$ cat /tmp/ll.log |grep 1
1
1
ushastry@ubuntu1204:~/Downloads$ cat /tmp/ll.log |grep 2|wc -l
17616
[28 Sep 2015 18:54] Paul DuBois
Noted in 5.6.28, 5.7.9, 5.8.0 changelogs.

The server initialization script used for the service mysql status
command on Linux sometimes incorrectly reported that the server was
stopped.