需求說明
系統配置低了,且應用程序內一直在執行定時任務,在程序運行一段時間后,發現接口請求會變得很慢,需要每天定時凌晨重啟服務器
腳本實現
1. linux 終端輸入crontab -e,添加定時任務腳本命令
[root@localhost ~]# crontab -e
2. 在文件末尾追加
0 0 * * * /sbin/reboot;
3. 重啟服務讓定時任務生效
systemctl restart crond
4. 配置定時任務開機自啟
查看服務是否開機自啟
systemctl list-unit-files|grep crond.service
如果沒有開機自啟,設置開機自啟
systemctl enable crond