Centos 7 systemd 服务启动时无法读取网络驱动器上的文件

Centos 7 systemd 服务启动时无法读取网络驱动器上的文件

我在网上读了很多与 systemd 相关的依赖项,但还是找不到一个能用的。我不确定问题出在哪里。该作业应该在重启时启动。它依赖于网络、autofs、rpc,我添加了 RequiresMountsFor,但还是没用。该单元仍然无法在网络驱动器上找到文件。任何想法都值得赞赏。

$ systemd-analyze critical-chain hello.service
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

hello.service @11.520s
└─autofs.service @11.429s +88ms
  └─network.target @11.425s
    └─network.service @10.751s +674ms
      └─NetworkManager.service @1.326s +123ms
        └─basic.target @1.274s
          └─sockets.target @1.274s
            └─rpcbind.socket @1.274s
              └─sysinit.target @1.273s
                └─systemd-update-utmp.service @1.269s +2ms
                  └─auditd.service @1.204s +62ms
                    └─systemd-tmpfiles-setup.service @1.120s +82ms
                      └─rhel-import-state.service @1.111s +8ms
                        └─local-fs.target @1.109s
                          └─home.mount @734ms +261ms
                            └─dev-mapper-centos\x2dhome.device @734ms

这是单元文件:

$ cat hello.service
[Unit]
Description=Hello Tester
Requires=network-online.target autofs.service
After=network-online.target autofs.service
RequiresMountsFor=/path/to/file

[Service]
ExecStart=/usr/bin/ls -l /path/to/file/on_nfs > /tmp/hello_tester.log

[Install]
WantedBy=multi-user.target

这是错误。我想我不能像那样指定带有多个参数的命令行。但很明显它在启动时无法在网络上看到该文件。

$ systemctl status hello.service
● hello.service - Hello Tester
   Loaded: loaded (/etc/systemd/system/hello.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sat 2016-07-30 02:18:02 HKT; 2 days ago
  Process: 1760 ExecStart=/usr/bin/ls -l /path/to/file/on_nfs > /tmp/hello_tester.log (code=exited, status=2)
 Main PID: 1760 (code=exited, status=2)

Jul 30 02:17:56 localhost.localdomain systemd[1]: Started Hello Tester.
Jul 30 02:17:56 localhost.localdomain systemd[1]: Starting Hello Tester...
Jul 30 02:18:02 localhost.localdomain ls[1760]: /usr/bin/ls: cannot access /path/to/file/on_nfs: No such file or directory
Jul 30 02:18:02 localhost.localdomain ls[1760]: /usr/bin/ls: cannot access >: No such file or directory
Jul 30 02:18:02 localhost.localdomain ls[1760]: /usr/bin/ls: cannot access /tmp/hello_tester.log: No such file or directory
Jul 30 02:18:02 localhost.localdomain systemd[1]: hello.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Jul 30 02:18:02 localhost.localdomain systemd[1]: Unit hello.service entered failed state.
Jul 30 02:18:02 localhost.localdomain systemd[1]: hello.service failed.

答案1

出于偏执,您是否尝试过以 root 用户身份登录时访问此文件?除非服务计算机授予 root 用户权限,否则 root 用户在 NFS 分区上不具有最高权限。

相关内容