🐧如何确定需要在Linux系统上重新启动哪些服务

使用Needrestart实用程序来确定升级后需要重新启动哪些服务。

安装Needrestart实用程序。

$ sudo apt install needrestart

让我们使用命令行显示摘要。

$ sudo needrestart --help
needrestart 3.4 - Restart daemons after library updates.
Authors:
  Thomas Liske <[email protected]>
Copyright Holder:
  2013 - 2018 (C) Thomas Liske [http://fiasko-nw.net/~thomas/]
Upstream:
  https://github.com/liske/needrestart
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Usage:
  needrestart [-vn] [-c <cfg>] [-r <mode>] [-f <fe>] [-u <ui>] [-bkl]
    -v		be more verbose
    -q		be quiet
    -m <mode>	set detail level
	e	(e)asy mode
	a	(a)dvanced mode
    -n		set default answer to 'no'
    -c <cfg>	config filename
    -r <mode>	set restart mode
	l	(l)ist only
	i	(i)nteractive restart
	a	(a)utomatically restart
    -b		enable batch mode
    -p          enable nagios plugin mode
    -f <fe>	overwrite debconf frontend (DEBIAN_FRONTEND, debconf(7))
    -u <ui>     use preferred UI package (-u ? shows available packages)
  By using the following options only the specified checks are performed:
    -k          check for obsolete kernel
    -l          check for obsolete libraries
    -w          check for obsolete CPU microcode
    --help      show this help
    --version   show version information

使用方便的输出检查需要重新启动的内容:

$ sudo needrestart -b
NEEDRESTART-VER: 3.4
NEEDRESTART-KCUR: 4.19.0-8-amd64
NEEDRESTART-KEXP: 4.19.0-9-amd64
NEEDRESTART-KSTA: 3
NEEDRESTART-SVC: exim4.service
NEEDRESTART-SVC: [email protected]

当前内核和预期内核之间存在差异,状态指示预期版本更新。 可能的状态:未知(0),无挂起更新(1),符合ABI的更新挂起(2),挂起版本更新(3)。

使用人类可读的输出来验证需要重新启动的内容(需要用户交互)。

$ sudo needrestart -u NeedRestart::UI::stdio -r l
Scanning processes...
Scanning candidates...
Scanning linux images...
Pending kernel upgrade!
Running kernel version:
  4.19.0-8-amd64
Diagnostics:
  The currently running kernel version is not the expected kernel version 4.19.0-9-amd64.
Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting. [Return]
Services to be restarted:
 systemctl restart exim4.service
 systemctl restart [email protected]
No containers need to be restarted.
No user sessions are running outdated binaries.

重新启动服务。

$ sudo needrestart -u NeedRestart::UI::stdio -r a
Scanning processes...
Scanning candidates...
Scanning linux images...
Pending kernel upgrade!
Running kernel version:
  4.19.0-8-amd64
Diagnostics:
  The currently running kernel version is not the expected kernel version 4.19.0-9-amd64.
Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting. [Return]
Restarting services...
 systemctl restart exim4.service [email protected]
No containers need to be restarted.
No user sessions are running outdated binaries.

再次,检查是否需要重新启动。

$ sudo needrestart -b
NEEDRESTART-VER: 3.4
NEEDRESTART-KCUR: 4.19.0-8-amd64
NEEDRESTART-KEXP: 4.19.0-9-amd64
NEEDRESTART-KSTA: 3

重新启动操作系统,然后检查是否需要重新启动。

$ sudo needrestart -b
NEEDRESTART-VER: 3.4
NEEDRESTART-KCUR: 4.19.0-9-amd64
NEEDRESTART-KEXP: 4.19.0-9-amd64
NEEDRESTART-KSTA: 1
$ sudo needrestart -u NeedRestart::UI::stdio -r l
Scanning processes...
Scanning linux images...
Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.

Sidebar