大网数据广告活动
服务器运维问答

How to make `needrestart` not defer restarting some services

· 52CE 我爱测

With unattended-upgrades duly set up to automatically do upgrades, reboots and all, I'm stumped to find output like this in its daily report sometimes: ... Restarting services... /etc/needrestart/restart.d/systemd-manager systemc…

问题原文

原帖链接 · cueedee · CC BY-SA 4.0

With unattended-upgrades duly set up to automatically do upgrades, reboots and all, I'm stumped to find output like this in its daily report sometimes:

...
Restarting services...
 /etc/needrestart/restart.d/systemd-manager
 systemctl restart accounts-daemon.service networkd-dispatcher.service polkit.service systemd-networkd.service systemd-resolved.service systemd-timesyncd.service systemd-udevd.service

Service restarts being deferred
 systemctl restart apt-daily-upgrade.service
 systemctl restart systemd-journald.service
 systemctl restart systemd-logind.service
 systemctl restart unattended-upgrades.service
...

I understand this is output from needrestart. I do not understand what sets the services that do get restarted apart from the ones that don't. What configuration do I need to change to make it restart all these services unattendedly?

已采纳解答

原帖链接 · BrokenBinary · CC BY-SA 4.0

The needrestart package maintains an exclusion list of services that should not be restarted automatically in /etc/needrestart/needrestart.conf. Look for the $nrconf{override_rc} setting.

Be careful modifying this list. Based on my quick glance, it seems like most of these default exclusions are due to user reported issues that arise when restarting services. A lot of the exclusions in that file have a comment with a Debian bug tracker number that explains why the exclusion is there.

Looking at the example in your question, these exclusions are causing your services to not be restarted automatically:

  • apt-daily-upgrade.service and unattended-upgrades.service aren't restarted because restarting those can kill the running needrestart process if it was started by those services. This is documented in bug #862840.
  • systemd-journald.service isn't being restarted because it breaks a lot of other services. This is documented in bug #771122. However, this question is 2 years old and this exclusion isn't present in newer versions (3.4+) of needrestart. It's not excluded on my Ubuntu 22.04 system.
  • systemd-logind.service isn't restarted because doing so kills your running X server session. This is documented in bug #798097.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-04-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。