0 fedora systemd systemd-timer
我正在尝试设置每 4 小时运行一次的 systemd 时间。当计时器触发时,运行脚本来更新一些数据文件。我每 2 小时在整点 30 分钟跟踪一次 systemd 计时器?和systemd 计时器每 15 分钟一次。
\n\n文件/etc/systemd/system/ftc-data.service:
[Unit]\nDescription=Fetch FTC Do Not Call data files\n\n[Service]\nType=oneshot\nExecStart=/var/ftc/ftc-data/fetch-data.sh\nRun Code Online (Sandbox Code Playgroud)\n\n文件/etc/systemd/system/ftc-data.timer:
[Unit]\nDescription=Run ftc-data.service every 4 hours\n\n[Timer]\nOnCalendar=00/4:00\n\n[Install]\nWantedBy=timers.target\nRun Code Online (Sandbox Code Playgroud)\n\n这就是问题出现的地方:
\n\nsystemctl enable /etc/systemd/system/ftc-data.timer\nsystemctl start /etc/systemd/system/ftc-data.timer\nsystemctl enable /etc/systemd/system/ftc-data.service\nRun 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.\nRun 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 太不一样了。
这是systemd.mount文档,但是如果我在读完它后能说出问题所在,那该死的。我不知道文件系统挂载与事物有什么关系。我想做的就是每 4 小时运行一个脚本。
\n\ncron我现在真的很想念。cron简单且有效。它已被替换为更复杂但不起作用的东西。叹...
需要修复什么(除了 systemd 之外)?
\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\nRun Code Online (Sandbox Code Playgroud)\n\nWeb 服务器可以访问,/var/ftc/ftc-data/因为它需要提供目录中的文档 另请参阅如何解决子目录中 Nginx 权限被拒绝的问题?
您应该提供单元的名称,而不是文件的路径。
你应该这样做:
systemctl enable ftc-data.timer
systemctl start ftc-data.timer
systemctl enable ftc-data.service
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2160 次 |
| 最近记录: |