Background

After upgrading some of our production servers to Ubuntu 24.04 (Noble), we began noticing unexpected MySQL restarts during routine package updates.
This was extremely concerning because these restarts happened without any DBA action and caused disruption on live workloads.

On investigation, we found the culprit: a change in the behavior of the needrestart package.


In Ubuntu 24.04, needrestart now restarts services automatically during apt upgrade or unattended-upgrades. Previously, in non-interactive mode, it only reported which services needed restarting but did not actually restart them. This change was meant to improve patch hygiene, but for production databases, it’s dangerous—because MySQL can be bounced in the middle of heavy traffic.


Symptoms We Observed

Here’s what we saw in the MySQL error log:

2025-09-23T06:03:25.902608Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>.
Shutting down mysqld (Version: 8.0.43-34).

There was no corresponding high load, crash, or OOM event.
Instead, in /var/log/messages we saw systemd/dbus activity triggered during package operations:

2025-09-23T06:03:25.424042+00:00 mysql-prod-shard dbus-daemon[2045]: [system] Activating via systemd: service name='org.freedesktop.PackageKit' unit='packagekit.service' requested by ':1.297' (uid=0 pid=1227540 comm="/usr/bin/gdbus call --system --dest org.freedesktop.PackageKit" label="unconfined")

This confirmed that it was not an internal MySQL crash but an external restart trigger.

We later saw similar patterns across multiple servers whenever unattended upgrades applied security patches.


The Root Cause

  • Ubuntu 24.04 ships needrestart with new defaults.
  • The /etc/apt/apt.conf.d/99needrestart file included the -m u flag, which forces automatic restarts of affected services during upgrades.
  • MySQL was one of those services.

The Fix We Applied

We restored the old behavior by editing:

File: /etc/apt/apt.conf.d/99needrestart

Before

DPKg::Post-Invoke { "if [ -x /usr/sbin/needrestart ]; then /usr/sbin/needrestart -m u; fi"; };

After

DPKg::Post-Invoke { "if [ -x /usr/sbin/needrestart ]; then /usr/sbin/needrestart; fi"; };

This disables the forced auto-restart and brings back the safer reporting-only behavior.


Recommendations

  • If you run production databases on Ubuntu 24.04, be aware of this needrestart change.
  • Either:
    • Remove the -m u flag (global rollback to old behavior), or
    • Configure /etc/needrestart/conf.d/ overrides to exempt critical services like mysql.service.
  • Avoid unattended restarts on DB servers—schedule controlled maintenance windows for patching.

Closing Thoughts

What looked like random MySQL crashes turned out to be a silent policy change in Ubuntu 24.04.
Lesson learned: **always review the upgrade notes and the features introduced before doing an OS upgrade for your critical services

This experience reinforced our principle:
Production DBs must never be restarted automatically by the OS.

Have you faced something similar on Ubuntu 24.04? Let me know in the comments.