在下面的服务中,如果我完全省略该WorkingDirectory
条目,systemd 可以解析该文件,但服务本身需要WorkingDirectory
设置。但是,每当它设置为这个特定目录时,我都会得到:
$ systemctl --user start valheim.service
Failed to start valheim.service: Unit valheim.service has a bad unit file setting.
我验证了所示目录是否正确且存在。
这是服务文件:
[Unit]
Description=Valheim Server
After=multi-user.target
[Service]
RemainAfterExit=False
WorkingDirectory="/home/brandon/.local/share/Steam/steamapps/common/Valheim dedicated server"
ExecStart="/home/brandon/.local/share/Steam/steamapps/common/Valheim dedicated server/start_emerlain.sh"
[Install]
WantedBy=default.target
我也尝试使用systemd-escape
:
$ systemd-escape --path "/home/brandon/.local/share/Steam/steamapps/common/Valheim dedicated server"
home-brandon-.local-share-Steam-steamapps-common-Valheim\x20dedicated\x20server
然后改为:
WorkingDirectory=home-brandon-.local-share-Steam-steamapps-common-Valheim\x20dedicated\x20server
(也尝试过使用双引号,但没有运气)。
使用建议的方法挖掘更多细节似乎遇到困难:
$ systemctl --user status valheim.service
Failed to parse bus message: No such device or address
编辑1
例如,我忘记提及设置WorkingDirectory="/home/brandon"
不会导致相同的问题 - systemd 似乎接受这个更简单的目录。
答案1
似乎这是 systemd 中的一个错误,现已修复。我在 RHEL 8 上使用 /usr/bin/env 使其可以使用以下解决方法。我将其更改为匹配您的用户名等。在更高版本的 systemd 中,您应该能够对带有空格的路径使用双引号或单引号。
[Unit]
Description=Valheim service
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
Restart=on-failure
RestartSec=10
User=brandon
WorkingDirectory=/home/brandon
ExecStart=/usr/bin/env -C "/home/brandon/.local/share/Steam/steamapps/common/Valheim dedicated server/" "/home/brandon/.local/share/Steam/steamapps/common/Valheim dedicated server/start_server.sh"
[Install]
WantedBy=multi-user.target