我之前做过这个新工作:
description "This is Notification Service"
author "King"
start on runlevel [2345]
exec watch -n 1 /usr/bin/curl -s https://domain.com/cron >/dev/null 2>&1
现在,我已将其转换为 systemd:
[Unit]
Description=This is Notification Service
[Service]
ExecStart=/bin/bash -c '/usr/bin/watch -n 1 /usr/bin/curl -s https://domain.com/cron >/dev/null 2>&1'
[Install]
WantedBy=multi-user.target
但它不起作用,我每次启动它时它总是失败。
● notify-fb.service - This is Notification Service
Loaded: loaded (/etc/systemd/system/notify-fb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2016-09-25 02:25:02 PST; 3h 53min ago
Process: 15299 ExecStart=/usr/bin/watch -n 1 /usr/bin/curl -s https://domain.com/cron (code=exited, status=1/FAILURE)
Main PID: 15299 (code=exited, status=1/FAILURE)
Sep 25 02:25:02 xxxx.com systemd[1]: Started This is Notification Service.
Sep 25 02:25:02 xxxx.com watch[15299]: Error opening terminal: unknown.
Sep 25 02:25:02 xxxx.com systemd[1]: notify-fb.service: Main process exited, code=exited, status=1/FAILURE
Sep 25 02:25:02 xxxx.com systemd[1]: notify-fb.service: Unit entered failed state.
Sep 25 02:25:02 xxxx.com systemd[1]: notify-fb.service: Failed with result 'exit-code'.
答案1
在您的输出中,有:
watch[15299]: 打开终端时出错:未知。
看起来可能watch
正在期望连接到 STDOUT 上的 TTY,但失败了。请参阅文档StandardOutput=
在 systemd.exec 中用于设置 TTY 的选项。
systemd 还可以完全取代使用“watch”的需要。看起来,这watch
只是每秒调用一次 URL。使用 systemd 计时器可以完成同样的事情。请参阅man systemd.timer
和man systemd.time
了解 systemd 计时器。