未找到 Systemd 计时器和挂载

0 fedora systemd systemd-timer

我正在尝试设置每 4 小时运行一次的 systemd 时间。当计时器触发时,运行脚本来更新一些数据文件。我每 2 小时在整点 30 分钟跟踪一次 systemd 计时器?systemd 计时器每 15 分钟一次

\n\n

文件/etc/systemd/system/ftc-data.service

\n\n
[Unit]\nDescription=Fetch FTC Do Not Call data files\n\n[Service]\nType=oneshot\nExecStart=/var/ftc/ftc-data/fetch-data.sh\n
Run Code Online (Sandbox Code Playgroud)\n\n

文件/etc/systemd/system/ftc-data.timer

\n\n
[Unit]\nDescription=Run ftc-data.service every 4 hours\n\n[Timer]\nOnCalendar=00/4:00\n\n[Install]\nWantedBy=timers.target\n
Run Code Online (Sandbox Code Playgroud)\n\n

这就是问题出现的地方:

\n\n
systemctl enable /etc/systemd/system/ftc-data.timer\nsystemctl start  /etc/systemd/system/ftc-data.timer\nsystemctl enable /etc/systemd/system/ftc-data.service\n
Run Code Online (Sandbox Code Playgroud)\n\n

命令的结果是:

\n\n
# systemctl enable /etc/systemd/system/ftc-data.timer\n\n# systemctl start  /etc/systemd/system/ftc-data.timer\nFailed to start etc-systemd-system-ftc\\x2ddata.timer.mount: Unit etc-systemd-system-ftc\\x2ddata.timer.mount not found.\n\n# systemctl enable /etc/systemd/system/ftc-data.service\nThe unit files have no installation config (WantedBy, RequiredBy, Also, Alias\nsettings in the [Install] section, and DefaultInstance for template units).\nThis means they are not meant to be enabled using systemctl.\nPossible reasons for having this kind of units are:\n1) A unit may be statically enabled by being symlinked from another unit\'s\n   .wants/ or .requires/ directory.\n2) A unit\'s purpose may be to act as a helper for some other unit which has\n   a requirement dependency on it.\n3) A unit may be started when needed via activation (socket, path, timer,\n   D-Bus, udev, scripted systemctl call, ...).\n4) In case of template units, the unit is meant to be enabled with some\n   instance name specified.\n
Run Code Online (Sandbox Code Playgroud)\n\n

看起来问题是在尝试启用时开始的ftc-data.timer。我试图理解它Failed to start etc-systemd-system-ftc\\x2ddata.timer.mount: Unit etc-systemd-system-ftc\\x2ddata.timer.mount not found.,但在搜索时没有找到命中结果。我在Newbie Corner \xc2\xbb Unit Timer上找到了一篇文章,但那家伙又重新使用 cron,因为定时器与 systemd 太不一样了。

\n\n

这是systemd.mount文档,但是如果我在读完它后能说出问题所在,那该死的。我不知道文件系统挂载与事物有什么关系。我想做的就是每 4 小时运行一个脚本。

\n\n

cron我现在真的很想念。cron简单且有效。它已被替换为更复杂但不起作用的东西。叹...

\n\n

需要修复什么(除了 systemd 之外)?

\n\n
\n\n

这是 Fedora 29 服务器,SELinux 处于强制模式。这可能与以下事情有关:

\n\n
# ls -Zd /var/ftc/ftc-data/fetch-data.sh\nunconfined_u:object_r:httpd_sys_content_t:s0 /var/ftc/ftc-data/fetch-data.sh\n
Run Code Online (Sandbox Code Playgroud)\n\n

Web 服务器可以访问,/var/ftc/ftc-data/因为它需要提供目录中的文档 另请参阅如何解决子目录中 Nginx 权限被拒绝的问题?

\n

Mic*_*ton 5

您应该提供单元的名称,而不是文件的路径。

你应该这样做:

systemctl enable ftc-data.timer
systemctl start ftc-data.timer
systemctl enable ftc-data.service
Run Code Online (Sandbox Code Playgroud)