要在Linux系統(tǒng)中使用Systemd管理Crontab任務(wù),需要執(zhí)行以下步驟:
sudo nano /etc/systemd/system/mycron.service
[Unit]
Description=Run crontab tasks
[Service]
ExecStart=/usr/bin/crontab /path/to/your/crontab/file
[Install]
WantedBy=multi-user.target
在ExecStart行中,將/path/to/your/crontab/file替換為你實(shí)際的crontab文件路徑。
保存并關(guān)閉文件。
使用以下命令重新加載Systemd配置文件:
sudo systemctl daemon-reload
sudo systemctl enable mycron
sudo systemctl start mycron
現(xiàn)在,你的Crontab任務(wù)將由Systemd來(lái)管理。
你可以使用以下命令來(lái)管理mycron服務(wù):
啟動(dòng)服務(wù):sudo systemctl start mycron
停止服務(wù):sudo systemctl stop mycron
重啟服務(wù):sudo systemctl restart mycron
禁用服務(wù):sudo systemctl disable mycron
你還可以使用以下命令來(lái)查看服務(wù)的狀態(tài):
sudo systemctl status mycron