Apt-get update / apt-get upgrade causes OH restart

I’m on OH 4.3.1 on Ubuntu 24.04.1 LTS. Recently I’ve found that every time I do an apt-get update followed by apt-get upgrade, OH restarts. I don’t believe this used to happen, but I’m unsure if it is because of my recent Ubuntu upgrade or because of OH itself. Is this normal now? Example below. Should the upgrade of the packages below trigger a restart of OH? What exactly does trigger an OH restart?

The following packages will be upgraded:
  bind9-dnsutils bind9-host bind9-libs dnsutils
4 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,460 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 bind9-host amd64 1:9.18.30-0ubuntu0.24.04.1 [50.4 kB]
Get:2 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 bind9-dnsutils amd64 1:9.18.30-0ubuntu0.24.04.1 [155 kB]
Get:3 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 bind9-libs amd64 1:9.18.30-0ubuntu0.24.04.1 [1,251 kB]
Get:4 http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 dnsutils all 1:9.18.30-0ubuntu0.24.04.1 [3,676 B]
Fetched 1,460 kB in 2s (760 kB/s)
(Reading database ... 171985 files and directories currently installed.)
Preparing to unpack .../bind9-host_1%3a9.18.30-0ubuntu0.24.04.1_amd64.deb ...
Unpacking bind9-host (1:9.18.30-0ubuntu0.24.04.1) over (1:9.18.28-0ubuntu0.24.04.1) ...
Preparing to unpack .../bind9-dnsutils_1%3a9.18.30-0ubuntu0.24.04.1_amd64.deb ...
Unpacking bind9-dnsutils (1:9.18.30-0ubuntu0.24.04.1) over (1:9.18.28-0ubuntu0.24.04.1) ...
Preparing to unpack .../bind9-libs_1%3a9.18.30-0ubuntu0.24.04.1_amd64.deb ...
Unpacking bind9-libs:amd64 (1:9.18.30-0ubuntu0.24.04.1) over (1:9.18.28-0ubuntu0.24.04.1) ...
Preparing to unpack .../dnsutils_1%3a9.18.30-0ubuntu0.24.04.1_all.deb ...
Unpacking dnsutils (1:9.18.30-0ubuntu0.24.04.1) over (1:9.18.28-0ubuntu0.24.04.1) ...
Setting up bind9-libs:amd64 (1:9.18.30-0ubuntu0.24.04.1) ...
Setting up bind9-host (1:9.18.30-0ubuntu0.24.04.1) ...
Setting up bind9-dnsutils (1:9.18.30-0ubuntu0.24.04.1) ...
Setting up dnsutils (1:9.18.30-0ubuntu0.24.04.1) ...
Processing triggers for libc-bin (2.39-0ubuntu8.3) ...
Processing triggers for man-db (2.12.0-4build2) ...
Scanning processes...
Scanning candidates...
Scanning processor microcode...
Scanning linux images...

Running kernel seems to be up-to-date.

The processor microcode seems to be up-to-date.

Restarting services...
 systemctl restart openhab.service

Have a look at

Thanks for that link. I did upgrade through several Ubuntu releases recently, so perhaps more has changed since what is described in the link. I suppose I should be happy that they are taking security very seriously and the OH restarts are a consequence of that, but I initially found it a bit disconcerting.

This is nuts. If you sneeze, OH restarts. See below - why would ‘packagekit.service’ force an OH restart? It seems like OH is restarting on all changes, not just changes that matter to it. I can see how to override the restarts globally in the needrestart, but that means I won’t get restarts when it should such as with a security update to library OH is using.

Anyone else running OH 4.3.2 on Ubuntu 24.04.1 LTS?

2025-01-31T06:46:38.763837-08:00 pl-nuc systemd[1]: Starting apt-daily-upgrade.service - Daily apt upgrade and clean activities...
2025-01-31T06:46:45.948825-08:00 pl-nuc apt.systemd.daily[160078]: /usr/bin/unattended-upgrade:567: DeprecationWarning: This process (pid=160078) is multi-threaded, use of fork() may lead to deadlocks in the child.
2025-01-31T06:46:45.949170-08:00 pl-nuc apt.systemd.daily[160078]:   pid = os.fork()
2025-01-31T06:46:49.068559-08:00 pl-nuc dbus-daemon[770]: [system] Activating via systemd: service name='org.freedesktop.PackageKit' unit='packagekit.service' requested by ':1.59' (uid=0 pid=160188 comm="/usr/bin/gdbus call --system --dest org.freedeskto" label="unconfined")
2025-01-31T06:46:49.080747-08:00 pl-nuc systemd[1]: Starting packagekit.service - PackageKit Daemon...
2025-01-31T06:46:49.107338-08:00 pl-nuc PackageKit: daemon start
2025-01-31T06:46:49.186704-08:00 pl-nuc dbus-daemon[770]: [system] Successfully activated service 'org.freedesktop.PackageKit'
2025-01-31T06:46:49.186854-08:00 pl-nuc systemd[1]: Started packagekit.service - PackageKit Daemon.
2025-01-31T06:46:50.532160-08:00 pl-nuc systemd[1]: Stopping openhab.service - openHAB - empowering the smart home...
2025-01-31T06:47:05.307471-08:00 pl-nuc systemd[1]: openhab.service: Deactivated successfully.
2025-01-31T06:47:05.308042-08:00 pl-nuc systemd[1]: Stopped openhab.service - openHAB - empowering the smart home.
2025-01-31T06:47:05.308181-08:00 pl-nuc systemd[1]: openhab.service: Consumed 1h 3min 5.738s CPU time, 1.4G memory peak, 0B memory swap peak.
2025-01-31T06:47:05.315910-08:00 pl-nuc systemd[1]: Started openhab.service - openHAB - empowering the smart home.
2025-01-31T06:47:11.657676-08:00 pl-nuc systemd[1]: apt-daily-upgrade.service: Deactivated successfully.
2025-01-31T06:47:11.660331-08:00 pl-nuc systemd[1]: Finished apt-daily-upgrade.service - Daily apt upgrade and clean activities.
2025-01-31T06:47:11.660627-08:00 pl-nuc systemd[1]: apt-daily-upgrade.service: Consumed 15.814s CPU time.

You can reconfigure behaviour creating a .conf file in /etc/needrestart/conf.d with

$nrconf(restart) = ‘l’;

a would be default cause an automatic restart during / after apt-get update or upgrade
i is interactive (asking?)
l is list only.

So with l you got a hint restart proposed, but is not do automatically.

Yes, thank you, I can do that. But what I’m puzzled with is why OH always seems to need a restart. I thought ‘needrestart’ would be smarter. It does not restart all services on every apt-get. Only OH gets restarted every time.

OpenHAB Uses a lot of Libraries and e.g. python gets updates very often.

There are ways to disclose services, but from Security reasons that may be a bad idea

I have put this in the /etc/needrestart/conf.d/openhab.conf

$nrconf{override_rc} = {
  qr(^openhab) => 0,
};

This seems to work for me - I’m informed that OH needs a restart, but I can do the restart when I choose and it is convenient rather than when an update has occurred.

Service restarts being deferred:
 systemctl restart openhab.service