[MDEV-5939] service mysql status command fails when run by normal user Created: 2014-03-24  Updated: 2020-05-19  Resolved: 2020-05-19

Status: Closed
Project: MariaDB Server
Component/s: Packaging, Server
Affects Version/s: 5.5.35
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Sanford Rockowitz Assignee: Otto Kekäläinen
Resolution: Fixed Votes: 0
Labels: packaging
Environment:

Ubuntu 13.10


Attachments: HTML File bug_output     HTML File mariadb     File my.cnf     HTML File show_mariadb_bug    
Issue Links:
Duplicate
duplicates MDEV-7247 service mysql status not availabe in ... Closed

 Description   

Command "service mysql status" fails when executed by a normal user. (It works for other services.) There are two reasons for this. First, the process id file is created with permissions 660, so it can't be read (most process id files have permissions 622). Second, the "kill -0" command used in the service file to determine if a process is active fails when executed by an arbitrary user.

Attached are a script demonstrating the problem and its output. Also attached are the my.cnf file and the service file (/etc/init.d/mariadb). The service file is lightly modified from the distributed support-files/mysql-server.

mariadb was installed from file mariadb-5.5.36-linux-x86_64.tar.gz



 Comments   
Comment by Sanford Rockowitz [ 2014-03-24 ]

oops, tested platform is Ubuntu 13.10, not 13.4 as stated.

Comment by Elena Stepanova [ 2015-06-02 ]

otto,

Does it also affect your packages, or is it MariaDB-packaging-specific?
Either way, is it a bug from Debian/Ubuntu perspective, and if it is, do you have suggestions about fixing it?

Thanks.

Comment by Otto Kekäläinen [ 2015-06-09 ]

Yes, this seems to affect all packaging.

$ apt-cache showpkg mariadb-server
Versions: 5.5.41-1ubuntu0.14.04.1
 
$ lsb_release -d
Description:    Ubuntu 14.04.2 LTS
 
$ sudo service mysql status
[sudo] password for otto: 
mysql start/running, process 13687
 
$ service mysql status
initctl: Unable to connect to system bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory

Comment by Otto Kekäläinen [ 2016-11-25 ]

This seems to be identical https://jira.mariadb.org/browse/MDEV-7247

If you rockowitz still think any of the changes you made should land in upstream, please make a pull request on the 10.2 branch.

Comment by Otto Kekäläinen [ 2020-05-19 ]

I tested this on latest MariaDB 10.5.3 RC on Ubuntu Bionic, and it works:

vagrant@ubuntu-bionic:~$ service mysql status
● mariadb.service - MariaDB 10.5.3 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Tue 2020-05-19 08:45:10 UTC; 10min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 12896 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
  Process: 12894 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 12674 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || e
  Process: 12663 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 12655 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
 Main PID: 12833 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 39 (limit: 1152)
   CGroup: /system.slice/mariadb.service
           └─12833 /usr/sbin/mysqld

As root you also see the log:

vagrant@ubuntu-bionic:~$ sudo service mysql status
● mariadb.service - MariaDB 10.5.3 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Tue 2020-05-19 08:45:10 UTC; 12min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 12896 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
  Process: 12894 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 12674 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || e
  Process: 12663 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 12655 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
 Main PID: 12833 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 38 (limit: 1152)
   CGroup: /system.slice/mariadb.service
           └─12833 /usr/sbin/mysqld
 
May 19 08:45:16 ubuntu-bionic /etc/mysql/debian-start[12906]: mysql
May 19 08:45:16 ubuntu-bionic /etc/mysql/debian-start[12906]: performance_schema
May 19 08:45:16 ubuntu-bionic /etc/mysql/debian-start[12906]: Phase 6/7: Checking and upgrading tables
May 19 08:45:16 ubuntu-bionic /etc/mysql/debian-start[12906]: Processing databases
May 19 08:45:16 ubuntu-bionic /etc/mysql/debian-start[12906]: information_schema
May 19 08:45:16 ubuntu-bionic /etc/mysql/debian-start[12906]: performance_schema
May 19 08:45:16 ubuntu-bionic /etc/mysql/debian-start[12906]: Phase 7/7: Running 'FLUSH PRIVILEGES'
May 19 08:45:16 ubuntu-bionic /etc/mysql/debian-start[12906]: OK
May 19 08:45:16 ubuntu-bionic /etc/mysql/debian-start[12976]: Checking for insecure root accounts.
May 19 08:45:16 ubuntu-bionic /etc/mysql/debian-start[12980]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables

This makes sense, as normal users don't have access to /var/log/mysql/ nor journalctl -u mariadb.

The old sysv init does not allow status info:

vagrant@ubuntu-bionic:~$ /usr/share/mysql/mysql.init status
cat: /var/run/mysqld/mysqld.pid: Permission denied
 * MariaDB is stopped.
vagrant@ubuntu-bionic:~$ sudo /usr/share/mysql/mysql.init status
 * /usr/bin/mysqladmin  Ver 9.1 Distrib 10.5.3-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
 
Server version		10.5.3-MariaDB-1:10.5.3+maria~bionic-log
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/run/mysqld/mysqld.sock
Uptime:			18 min 7 sec
 
Threads: 23  Questions: 684  Slow queries: 0  Opens: 180  Open tables: 37  Queries per second avg: 0.629

This is because it uses mysqladmin which in turn needs access to the database (cannot be allowed to any user) and also it reads the pid file which is not visible system wide.

vagrant@ubuntu-bionic:~$ sudo ls -la /var/run/mysqld/mysqld.pid
-rw-rw---- 1 mysql mysql 6 May 19 08:45 /var/run/mysqld/mysqld.pid
 
vagrant@ubuntu-bionic:~$ mysqladmin ping
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'vagrant'@'localhost' (using password: NO)'
 
vagrant@ubuntu-bionic:~$ sudo mysqladmin ping
mysqld is alive

Comparison to other pid files:

vagrant@ubuntu-bionic:~$ sudo find /run/ -name *.pid -ls
      545      4 -rw-rw----   1 mysql    mysql           6 May 19 08:45 /run/mysqld/mysqld.pid
      521      4 -rw-r--r--   1 root     root            5 May 19 07:34 /run/sshd.pid
      506      4 -rw-r--r--   1 root     root            5 May 19 07:34 /run/crond.pid
      492      4 -rw-r--r--   1 root     root            4 May 19 07:34 /run/rsyslogd.pid
      429      4 -rw-r--r--   1 root     root            5 May 19 07:34 /run/atd.pid
      477      4 -rw-------   1 root     root            5 May 19 07:34 /run/lxcfs.pid
      283      4 -rw-r--r--   1 root     root            4 May 19 07:34 /run/lvmetad.pid

Changing the pid access does not help, it just leads to false message of service being stopped:

vagrant@ubuntu-bionic:~$ sudo chmod 644 /run/mysqld/mysqld.pid
vagrant@ubuntu-bionic:~$ /usr/share/mysql/mysql.init status
 * MariaDB is stopped.

To fix this would require rewriting the init script. Since the original command 'service mysql status' now uses systemd in most systems, and it works, I deem the original use case already solved and thus close this issue.

Generated at Thu Feb 08 07:08:10 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.