卸载之前运行 systemd 服务

卸载之前运行 systemd 服务

我试图在关闭时运行 systemd 服务:它有点工作(它被调用),但它在文件系统卸载后运行,这不是我需要的。所以我尝试了,有运气Before=umount.targetWantedBy=umount.target没有运气(在运行服务之前卸载文件系统)。当我说“文件系统”时,我指的是除根之外的所有文件系统。

还有其他需要注意的目标吗?

答案1

尝试添加DefaultDependencies=no到服务文件的 Unit 部分。 系统服务手册页说:

除非设置 DefaultDependency=no,否则将添加以下依赖项:

  •   Service units will have dependencies of type Requires= and After= on sysinit.target, a dependency of type After= on basic.target as well
      as dependencies of type Conflicts= and Before= on shutdown.target. These ensure that normal service units pull in basic system
      initialization, and are terminated cleanly prior to system shutdown. Only services involved with early boot or late system shutdown
      should disable this option.

...

相关内容