systemd 是否有工作目录说明符

mur*_*ngu 2 systemd

当我在单元文件中指定工作目录时,我想通过说明符从 ExecStart 部分引用它,即

[Unit]
Description=A test daemon that says hello
[Service]
Type=oneshot
WorkingDirectory=/home/foo/scipts
ExecStart="%<<WORKING_DIRECTORY_SPECIFIER>>/echo_hello.sh"
RemainAfterExit=yes
Run Code Online (Sandbox Code Playgroud)

Systemd 可以实现这一点吗?如果不行,有什么解决方法吗?

ku4*_*eto 5

您不需要在 中专门指定工作目录ExecStart,因为所有命令都将启动,就像您已经指定它一样。这就是重点。

您不应该使用~,因为这将使用服务运行时的$HOME$USER相反,使用相对路径。

如果你WorkingDirectory指向/home/foo/scripts/,那么你只需要使用ExecStart=./somescript.sh 如果你有子目录,它是一样的 - ExecStart=subdir1/subdir2/somescript.shWorkingDirectory基本上是一个cd针对服务的。