温馨提示×

ubuntu定时器怎样重启

小樊
50
2026-10-12 20:28:35
栏目: 智能运维

在 Ubuntu 中,“定时器”通常指 systemd 的 timer(类似 cron 的现代化方案),也可能指 cron 服务。下面分别说明。


一、如果是 systemd Timer(推荐方式)

1. 查看 timer 状态

systemctl list-timers
systemctl status your-task.timer

2. 重启某个 timer

sudo systemctl restart your-task.timer

3. 停止 / 启动

sudo systemctl stop your-task.timer
sudo systemctl start your-task.timer

4. 重新加载配置(修改了 .timer 或 .service 后)

sudo systemctl daemon-reload
sudo systemctl restart your-task.timer

5. 设置开机自启

sudo systemctl enable your-task.timer

二、如果是 cron(传统定时任务)

1. 修改 cron 后无需“重启”,但可重启服务

sudo systemctl restart cron

2. 查看 cron 状态

systemctl status cron

3. 编辑定时任务

crontab -e        # 当前用户
sudo crontab -e   # root 用户

三、常见误区

  • ❌ restart cron.timer(不存在)
  • ✅ restart cron(服务名)
  • ✅ restart xxx.timer(systemd timer)

四、示例

假设你有一个:

/etc/systemd/system/backup.timer
/etc/systemd/system/backup.service

重启方式:

sudo systemctl daemon-reload
sudo systemctl restart backup.timer

如果你能告诉我:

  • 用的是 cron 还是 systemd timer
  • timer / 任务名称是什么

我可以给你更精确的命令。

0 踩