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

Restart all services in Linux without rebooting kernel?

· 52CE 我爱测

I have remote machine that has encrypted drives thus each full reboot requires physical access to machine. Machine just experienced issues with lack of disk space so part of running services crashed / entered weird malfunction st…

问题原文

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

I have remote machine that has encrypted drives thus each full reboot requires physical access to machine. Machine just experienced issues with lack of disk space so part of running services crashed / entered weird malfunction states. I'd like to "soft reboot" machine without actually rebooting entire kernel to avoid remounting drives and necessity to enter passphrase.

OS is using systemd for services management and kernel 4.9.

已采纳解答

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

I have used with mixed success (these shortcuts are "available for compatibility only")

init 1; init 3

Which, nowadays typically translates to this:

systemctl isolate rescue; systemctl isolate default

Which kills everything except services that are deemed essential or part of the targets specified - systemd still provides targets that roughly mimic part of what runlevels used to to.

systemctl isolate UNIT

Start the unit specified on the command line and its dependencies and stop all others, unless they have IgnoreOnIsolate=yes (see systemd.unit(5)). If a unit name with no extension is given, an extension of ".target" will be assumed. - man 1 systemctl

The reason I do not quite like to recommend this, is exactly the killing part:

This is similar to changing the runlevel in a traditional init system. The isolate command will immediately stop processes that are not enabled in the new unit, possibly including the graphical environment or terminal you are currently using. - man 1 systemctl

I tried it on Ubuntu and figured i preferred if ssh.service and network.target were part of my rescue.target. Because it sure is safer if only services except ssh and its networking dependencies were restarted.

Because if something goes wrong while activating rescue.target, the command above might otherwise both kill my session and fail to bring everything back up.

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

资料来源与适用范围

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

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

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