Timer 如何配置systemd计时器的结束时间

Timer 如何配置systemd计时器的结束时间,timer,systemd,coreos,Timer,Systemd,Coreos,我正在使用CoreOS和SystemD计时器运行我的报告 我有一些监控报告需要在接下来的12小时内每3小时运行一次,运行时间为半小时。如果我想在1230醒着停止报告,那么这很容易实现 systemd timers>中是否有“terminate timer”(终止计时器)选项或类似选项?我相信您可以在服务文件的[Unit]指令中添加以下内容: JobTimeoutSec=43200 您可能只需编写一个包装器脚本,在12小时后终止进程,或者使用timeout 12h命令[ARG]…您只需编写另一个

我正在使用CoreOS和SystemD计时器运行我的报告

我有一些监控报告需要在接下来的12小时内每3小时运行一次,运行时间为半小时。如果我想在1230醒着停止报告,那么这很容易实现


systemd timers>中是否有“terminate timer”(终止计时器)选项或类似选项?我相信您可以在服务文件的[Unit]指令中添加以下内容:

JobTimeoutSec=43200

您可能只需编写一个包装器脚本,在12小时后终止进程,或者使用
timeout 12h命令[ARG]…

您只需编写另一个计时器,该计时器计划在您希望的关机时间运行。他们可以运行一项服务,通过在名为“关机计时器”的服务文件中运行
ExecStart=/bin/systemctl stop other.service
,来停止您想要添加的服务


我查看了
man-systemd.unit
中的
JobTimeoutSec
文档,似乎不太适合这份工作

可以在一定时间后终止systemd服务

Type=simple
服务使用
RuntimeMaxSec
选项:

[Unit]
Description=Terminate simple Service Test

[Service]
Type=simple
RuntimeMaxSec=5
ExecStart=/bin/sleep 10
[Unit]
Description=Terminate oneshot Service Test

[Service]
Type=oneshot
TimeoutStartSec=5
ExecStart=/bin/sleep 10
Type=oneshot
服务使用
timeoutpartsec

[Unit]
Description=Terminate simple Service Test

[Service]
Type=simple
RuntimeMaxSec=5
ExecStart=/bin/sleep 10
[Unit]
Description=Terminate oneshot Service Test

[Service]
Type=oneshot
TimeoutStartSec=5
ExecStart=/bin/sleep 10
这两项服务将在睡眠计时器达到10秒之前的5秒后终止

有关
RuntimeMaxSec
timeoutpartsec
的详细信息可在此处找到: