我正在调试SystemD关闭问题。这里的问题是,在服务仍在运行时,一些文件系统已卸载。
通常,我们希望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=
在开始期间的倒置是倒置的:必须在停止安装之前完全停止服务。
添加了重点的相关文档。文档没有提及停止期间发生的事情,但我确认它可以按照我们的期望。
bindsto =
配置需求依赖项,样式非常相似,与需求=。但是,这种依赖性类型更强:此外为了效果= =它声明,如果单位绑定到IS停止,该单元也将被停止。这意味着一个单位绑定到突然进入非活动状态的另一个单位也将停止。单位可以突然,出乎意料地输入不同的状态原因:服务单元的主要过程可能自己终止选择,设备单元的背衬设备可能会被拔下或安装单元的安装点可能会被卸下,而无需参与系统和服务经理。
与Arch = Arch =在同一单元上使用时,bindsto =甚至更强。在这种情况下,该单元严格绑定必须处于活跃状态才能使本机也处于活动状态。这不仅意味着一个绑定到另一个单位的单位突然进入不活跃的状态,也是一个绑定到另一个单位的状态由于条件检查失败而跳过(例如,条件路径师=,条件性pathissymboliclink =,… - 见下文(将停止,应它正在运行。因此,在许多情况下,最好结合bindsto =after =。
bindsto = b。在a.service上使用服务时,此依赖性将显示作为b.b.service的属性上市中的bundby = a.Service。bundby =无法直接指定依赖关系。