我有如下所示的服务,但是如何添加在满足某些条件时停止/终止服务的条件,例如 /tmp/killsoc 文件存在?
[Unit]
Description=Socat tunnel service
[Service]
ExecStart=/usr/bin/socat tcp-l:31120,fork,reuseaddr tcp:127.0.0.1:6443
答案1
也许使用这些条件之一ConditionPathExists=
ConditionArchitecture=、ConditionVirtualization=、ConditionHost=、
ConditionKernelCommandLine=、ConditionSecurity=、ConditionCapability=、ConditionACPower=、ConditionNeedsUpdate=、ConditionFirstBoot=、ConditionPathExists=、ConditionPathExistsGlob=、ConditionPathIsDirectory=、ConditionPathIsSymbolicLink=、ConditionPathIsMountPoint=、ConditionPathIsReadWrite=、ConditionDirectoryNotEmpty=、ConditionFileNotEmpty= , ConditionFileIsExecutable=
更多详细信息请参见:https://www.freedesktop.org/software/systemd/man/systemd.unit.html