在 Ubuntu 中,“定时器”通常指 systemd 的 timer(现代 Ubuntu 默认使用 systemd)。下面分情况说明**重载(reload/重新加载配置)**的方法。
.timer 或 .service 文件后如果你改了:
/etc/systemd/system/xxx.timer/etc/systemd/system/xxx.service需要先让 systemd 重新读取配置:
sudo systemctl daemon-reload
如果 timer 文件有变动,建议重新启用:
sudo systemctl disable xxx.timer
sudo systemctl enable xxx.timer
sudo systemctl restart xxx.timer
或只重新加载(timer 一般不支持 reload,用 restart 更稳妥):
sudo systemctl stop xxx.timer
sudo systemctl start xxx.timer
systemctl status xxx.timer
systemctl list-timers
sudo systemctl daemon-reload
sudo systemctl restart xxx.timer
⚠️ 注意:
OnCalendar 修改后必须 restart,否则不会按新时间触发Ubuntu 也支持 cron:
crontab -e
修改保存后,cron 会自动加载,一般不需要手动操作。
sudo systemctl restart cron
| 类型 | 重载命令 |
|---|---|
| systemd timer | systemctl daemon-reload + restart |
| cron | 自动生效,必要时 restart cron |
如果你愿意,可以告诉我:
.timer 或 crontab 内容我可以帮你给出精确的重载步骤。