[英]filesystem are unmounted before the services are stopped in systemd
我正在调试systemd shutdown问题。 这里的问题是在服务仍在运行时卸载了一些文件系统。
通常,我们希望systemd先关闭服务然后卸载挂载点。
但在这里,umount和停止服务正在并行发生。 (见下文)。 首先还要卸载根文件系统。
# Unmounting /root...
Unmounting /var/lib/ntp...
Unmounting /etc/cron.d/local...
[ OK ] Stopped Apply Kernel Variables.
Unmounting /proc/fs/nfsd...
Unmounting /tmp/rshell/trace...
Stopping Availability of block devices...
Unmounting /etc/timestamp...
Unmounting /var/lib/nfs/rpc_pipefs...
Unmounting /etc/sysconfig/clock...
[ OK ] Removed slice system-getty.slice.
[ OK ] Stopped Load Kernel Modules.
Unmounting /etc/ssh/ssh_external_host_rsa_key...
[ OK ] Stopped Create Static Device Nodes in /dev.
Unmounting /mnt/log...
[ OK ] Stopped Resets System Activity Logs.
Stopping Crond Periodic Command Scheduler...
[ OK ] Stopped Mount Restricted SFTP Jail Folders.
[ OK ] Stopped Mount Restricted Shell Folders.
Stopping Runs processtat...
Unmounting /etc/ssh/ssh_external_host_ecdsa_key.pub...
[ OK ] Stopped target RPC Port Mapper.
Unmounting /boot...
Unmounting /srv...
Stopping Initializes network console logging...
[ OK ] Stopped Crond Periodic Command Scheduler.
[FAILED] Failed unmounting /root.
[ OK ] Unmounted /var/lib/ntp.
[ OK ] Unmounted /etc/cron.d/local.
**[FAILED] Failed unmounting /mnt/sysimg.**
[ OK ] Unmounted /etc/sysconfig/clock.
[ OK ] Unmounted /usr/share/cracklib.
**[FAILED] Failed unmounting /run/netns.**
[ OK ] Unmounted /tftpboot/state.
**[FAILED] Failed unmounting /tmp/ldap.**
我们如何在systemd中同步这个?
通常,systemd-reboot.service依赖于final.target,shutdown.target和umount.target。
这看起来像是,umount.target和shutdown.target是并行执行的。
# cat /usr/lib/systemd/system/systemd-reboot.service
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Reboot
Documentation=man:systemd-halt.service(8)
DefaultDependencies=no
Requires=shutdown.target umount.target final.target
After=shutdown.target umount.target final.target
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl --force reboot
我试过,umount.target依赖于shutdown.target,但没有帮助。 总是这些umount和服务关闭似乎并行发生。 如果我的理解有误,请更正。
请提供一些提示/建议,以便首先正确关闭服务,然后卸载挂载点。
在您的服务单元中,尝试以下操作
BindsTo=mymount.mount
After=mymount.mount
mymount.mount
必须已经存在。 在我的例子中,我让systemd根据/etc/fstab
内容生成/var/run/systemd/generator/mymount.mount
。
BindsTo=
表示必须启动挂载才能启动服务,并且如果挂载已停止,则必须停止服务。 但两个单位仍然可以并行(几乎)并行启动和停止。 你需要另一个约束。 在服务启动之前,安装必须达到活动状态。 你会用After=
实现这个目标。 与其他systemd指令一样,启动期间After=
do在停止期间被反转:服务必须在挂载停止之前完全停止。
重点补充了相关文件。 该文件没有提到停止期间发生的事情,但我确认它的工作正如我们所期望的那样......
BindsTo =
配置需求依赖项, 风格与Requires =非常相似。 但是,这种依赖类型更强:除了Requires =的效果之外,它声明如果绑定的单位被停止,该单位也将被停止 。 这意味着绑定到突然进入非活动状态的另一个单元的单元也将被停止。 由于不同的原因,单元可能会突然意外地进入非活动状态:服务单元的主进程可能会根据自己的选择终止,可能会拔出设备单元的后备设备,或者可能卸载安装单元的安装点而不涉及系统和服务经理。
当与After =在同一单位上使用时,BindsTo =的行为甚至更强。 在这种情况下,严格必须处于活动状态的单元也必须处于活动状态。 这不仅意味着一个单元绑定到另一个突然进入非活动状态的单元,而且还绑定到另一个单元,该单元由于条件检查失败而被跳过(例如ConditionPathExists =,ConditionPathIsSymbolicLink =,...... - 见下文)将是它应该停止运行。 因此,在许多情况下,最好将BindsTo =与After =结合使用。
当在a.service上使用BindsTo = b.service时,此依赖关系将在b.service的属性列表中显示为BoundBy = a.service。 BoundBy =依赖项不能直接指定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.