MySQL cannot write slow logs to /dev/stderr

  • MySQL is running as a non-root user, under the name of mysql .
  • The Docker container is running Alpine, obviously, nay, righteously.
  • The usual steps taken to make sure non-root users can write to /dev/stderr and /dev/stdout seem to be failing pretty hard.
  • It snows in New York City for the first time in 2020, on the third week of January (totally related).
  • I write yet another Medium article with my future self as the main audience.
  • TL;DR: I do not achieve the outcome I am pursuing (writing slow logs to stdio). However, I mention some alternatives at the end of my story. If you’re looking for the solution and not the journey, skip all the way to the end of the story — most of this story (as typical of my stories) is all about the journey. Since I’m in it, why not share it while I’m at it?
Source: wikipedia
2020-01-19  9:08:10 0 [ERROR] mysqld: Can't seek in file '/dev/stderr' (Errcode: 29 "Invalid seek")2020-01-19  9:08:10 0 [ERROR] Could not use /dev/stderr for logging (error 29). Turning logging off for the whole duration of the MariaDB server process. To turn it on again: fix the cause, shutdown the MariaDB server and restart it.
In Alpine, only root and tty can write to pseudo-teletypes (PTS) device zero.

Steps to ensure non-root writes to stdio in Alpine Linux

  1. Add non-root user to group tty .
  2. Ensure tty is provisioned either via docker run or docker-compose .
  3. Ensure Docker process is in fact attempting to write logs to /dev/stdout or /dev/stderr .
Credit: github

Confirming non-root user access to stdio

  1. Check non-root user mysql has access to Alpine group tty
docker-compose run --rm --user=mysql --entrypoint=ash mysql
/ $ groups
mysql tty
Confirmed: tty is allocated for non-root user in docker-compose.yml
/ $ echo "hi" > /dev/stdout
hi

All permissions verified, MySQL still refusing to write log to stdio

su-exec mysql /usr/bin/mysqld \
--skip-name-resolve \
--skip-host-cache \
--skip-slave-start \
--debug-gdb \
--slow-query-log-file=/dev/stderr \
--slow-query-log
Cant run two database processes at once using the same Docker volume
  • Running as mysql user using the --user=mysql flag.
  • I am preventing the mysql process from starting by specifying --entrypoint=ash .
Error reproduced. Being able to manually reproduce the issue is always a good thing.
2020-01-19  9:08:10 0 [ERROR] mysqld: Can't seek in file '/dev/stderr' (Errcode: 29 "Invalid seek")2020-01-19  9:08:10 0 [ERROR] Could not use /dev/stderr for logging (error 29). Turning logging off for the whole duration of the MariaDB server process. To turn it on again: fix the cause, shutdown the MariaDB server and restart it.

Some more research

-T  Disable pseudo-tty allocation. By default `docker-compose run` allocates a TTY.
/ # chmod o+w /dev/stdout /dev/stderr
Credit: github
stdio links to file descriptors, file descriptors link to pts zero
Confirmed tty has read-write to pts/0

Trying an old hat trick

ln -sf /dev/stderr /tmp/err.log
su-exec mysql /usr/bin/mysqld \
--skip-name-resolve \
--skip-host-cache \
--skip-slave-start \
--debug-gdb \
--slow-query-log-file=/tmp/err.log \
--slow-query-log
Writing to a link that points to stdio
su-exec mysql /usr/bin/mysqld \
--skip-name-resolve \
--skip-host-cache \
--skip-slave-start \
--debug-gdb \
--slow-query-log-file=/tmp/errordotlog \
--slow-query-log
But a regular unix file works just fine!
Here’s the regular slow log file and it’s contents

What the heck is TTY and PTS?

  1. Teleprinters. Electro-mechanical devices for encoding, transmitting, decoding, and printing messages over long distances using telegraphy.
Source: wikipedia
VT100 terminal. Source: wikipedia

No Clean Solution

--

--

--

Organic, fair-sourced DevOps and Full-Stack things. This is a BYOB Establishment — Bring Your Own hipster Beard.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

When I prevented the situation to go out of hand

I guess Ananya’s situation looked familiar.

How to Get WooCommerce Cart Items Info?

How to Get WooCommerce Cart Items Info?

Structure and Content of Software Development

How to Clone Git Branch Repository?

How to Clone Git Branch Repository?

Quick intro to get started coding!!!

Error: re-routing — Makers Day 41

How to Use R with Google Colab Notebook

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

Callback Insanity

Organic, fair-sourced DevOps and Full-Stack things. This is a BYOB Establishment — Bring Your Own hipster Beard.

More from Medium

Setup and Secure MQTT websocket broker with Nginx

Getting Started with Docker — Part 01

Setting up Kibana for Elasticsearch in Local

Pass secrets to Docker build to fetch private Github repositories