我正在调试系统关闭问题。这里的问题是,有些文件系统是在服务仍在运行时卸载的。
通常,我们希望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和service关闭似乎是并行发生的。如果我的理解有误,请纠正。
请提供一些提示/建议,以正确关闭服务首先,然后卸载安装点。
发布于 2018-10-18 20:29:16
在您的服务单元中,尝试以下操作
BindsTo=mymount.mount
After=mymount.mountmymount.mount必须已经存在。在我的例子中,我让systemd基于/var/run/systemd/generator/mymount.mount内容生成/etc/fstab。
BindsTo=意味着必须启动挂载才能启动服务,如果挂载停止,则必须停止服务。但这两个单位仍然可以同时启动和停止(几乎)。你需要另一个约束。在服务启动之前,挂载必须达到活动状态。您将通过After=实现这一点。与其他systemd指令一样,After=在start期间所做的操作在停止期间是倒转的:在挂载停止之前,服务必须完全停止。
重点补充了有关文件。医生没有提到停站期间发生了什么,但我确认了它的工作效果,正如我们所期望的。
BindsTo= 配置需求依赖项,在样式上与Requires=非常相似。但是,这种依赖类型更强:除了Requires=的作用外,它还声明如果绑定到的单元被停止,这个单元也将停止。这意味着绑定到另一个突然进入非活动状态的单元也将停止。由于不同的原因,单元可能突然意外地进入非活动状态:服务单元的主进程可能自行终止,设备单元的后备设备可能被拔出,或者安装单元的安装点可能在没有系统和服务管理器参与的情况下被卸载。 当和After=一起使用在同一个单元上时,BindsTo=的行为甚至更强。在这种情况下,绑定的单元必须处于活动状态才能使该单元也处于活动状态。这不仅意味着绑定到另一个突然进入非活动状态的单元,还意味着绑定到另一个由于失败状态检查而跳过的单元(例如ConditionPathExists=、ConditionPathIsSymbolicLink=、…)。因此,在许多情况下,最好将BindsTo=与After=相结合。 当BindsTo=b.service在a.service上使用时,此依赖项将在b.service的属性列表中显示为BoundBy=a.service。不能直接指定BoundBy=依赖项。
https://stackoverflow.com/questions/48687099
复制相似问题