有没有办法在 systemd 单元中使用通配符、重定向或其他 shell 语法?

Jan*_*ith 5 services systemd wildcards

我有一个 systemd 文件来启动一个 jar 文件。但我想将 jar 文件作为*.jar. 有没有办法做到这一点?

[Unit]
Description=Test Background

[Service]
ExecStart=/usr/bin/java -jar /var/www/test.com/*.jar
Type=simple
WorkingDirectory=/var/www/test.com

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

我试过这个但没有用。

mur*_*uru 5

来自man 5 systemd.service(“命令行”部分):

This syntax is inspired by shell syntax, but only the meta-characters and expansions
described in the following paragraphs are understood, and the expansion of variables is
different. Specifically, redirection using "<", "<<", ">", and ">>", pipes using "|",
running programs in the background using "&", and other elements of shell syntax are not
supported.
Run Code Online (Sandbox Code Playgroud)

和:

Note that shell command lines are not directly supported. If shell command lines are to be
used, they need to be passed explicitly to a shell implementation of some kind. Example:

   ExecStart=/bin/sh -c 'dmesg | tac'
Run Code Online (Sandbox Code Playgroud)

通配符没有被提及为受支持,因此您必须在上面的示例中/bin/sh -c/bin/bash -c类似地包装该命令。