[英]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.