$ cat /etc/systemd/system/systemd-poweroff.timer
[Unit]
Description=Poweroff every work day
# Call necessary service
Unit=systemd-poweroff.service
[Timer]
# Power off in working days at 23:00
OnCalendar=Mon,Tue,Wed,Thu,Fri *-*-* 23:00:00
[Install]
WantedBy=timers.target
$ systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
Thu 2018-04-19 19:39:36 MSK 14min left n/a n/a systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Thu 2018-04-19 23:00:00 MSK 3h 34min left n/a n/a systemd-poweroff.timer systemd-poweroff.service
2 timers listed.
Pass --all to see loaded but inactive timers, too.
如果您想在特定日期禁用计时器,那么仅在普通 systemd 服务的情况下才有可能:
# systemctl stop systemd-poweroff.timer
# systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
Thu 2018-04-19 19:39:36 MSK 12min left n/a n/a systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
1 timers listed.
Pass --all to see loaded but inactive timers, too.
CentOS 7 有
systemd
初始化系统。systemd
有一个很好的特性,它被命名为timer
. 定时器类似于服务,用于在特定时间启动服务。systemd
通过调用systemd-poweroff
服务关闭系统。所以需要写systemd-poweroff.timer
:它需要做
systemctl enable systemd-poweroff.timer
和systemctl start systemd-poweroff.timer
启用和运行计时器。之后,将启动计时器:如果您想在特定日期禁用计时器,那么仅在普通 systemd 服务的情况下才有可能: