简体   繁体   English

从systemd单元文件运行时,无法打开目录

[英]When running from systemd unit file, unable to open directory

I have a strange problem with Ubuntu 16 and a systemd unit file. 我对Ubuntu 16和systemd单位文件有一个奇怪的问题。 I have a service which reads a directory from the local filesystem. 我有一个从本地文件系统读取目录的服务。 The directory is read from an environment variable. 该目录是从环境变量读取的。 Now when I start the service manually (as in: in a ssh session), everything works fine. 现在,当我手动启动服务时(如在ssh会话中),一切正常。 But when I start the service with the unit file from below, the service is unable to open the storage directory. 但是,当我从下面使用单位文件启动服务时,该服务无法打开storage目录。 The error I get is: could nog read contents of storage" message="open /srv/services/poddy/storage: no such file or directory . 我得到的错误是: could nog read contents of storage" message="open /srv/services/poddy/storage: no such file or directory

Now my question is: does systemd kind of "sandbox" the services? 现在我的问题是:系统化的服务会“沙盒化”吗?

[Unit]
Description=Poddy service
After=network.target

[Service]
Type=simple
User=myusername
Group=myusername
WorkingDirectory=/srv/services/poddy
ExecStart=/srv/services/poddy/poddy
Restart=always
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
Environment=PODDY_STORAGE="/srv/services/poddy/storage"
Environment=PODDY_PORT=8085

[Install]
WantedBy=multi-user.target

Well, I solved it myself. 好吧,我自己解决了。 It turns out that quoting the value of an environment var in the systemd unit file eventually double-escaped the value. 事实证明,在systemd单元文件中引用环境var的值最终会对该值进行两次转义。

So, changing this: 因此,更改此:

Environment=PODDY_STORAGE="/srv/services/poddy/storage"

into: 变成:

Environment=PODDY_STORAGE=/srv/services/poddy/storage

solved my problem :). 解决了我的问题:)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM