使用 systemd 启动 autofs 后如何设置服务启动

Reg*_*00x 9 rhel systemd

我必须在带有 systemd 的 RHEL7 机器上设置许可证服务器。许可证服务器应在引导时启动并从网络上的共享磁盘加载许可证文件。所以我需要等待网络启动和 autofs 完成挂载 NFS 磁盘。我有这个服务文件:

[Unit]
Description=Flexnet license server
Wants=network.target network-online.target autofs.service
After=network.target network-online.target autofs.service

[Service]
Type=forking
User=licenseuser
Group=devusers
ExecStart=/soft/flexera/glnxa64/lmgrd -c /soft/licenses/license.dat -L /home/licenseuser/license.log

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

该服务在 autofs 启动后但在 autofs 安装所有磁盘之前启动,因此无法启动许可证服务器。

小智 9

您应该添加以下内容

[Unit]
RequiresMountsFor=<path required>
Run Code Online (Sandbox Code Playgroud)

这将确保在启动服务之前可以访问该路径,并且如果它尚未安装(除非它指定了 noauto),也会安装它。如果您的系统支持该选项,请查看您的联机帮助页(man systemd.unit),因为我的系统非常先进。