首页>>帮助中心>>linux云服务器设置定时重启

linux云服务器设置定时重启

2023/6/4 733次
Linux定时重启vps服务器

1、首先创建一个新的systemd服务,这里创建的是reboot.service:
touch /etc/systemd/system/reboot.service

2、然后编辑文件:vi /etc/systemd/system/reboot.service

3、在文件输入以下内容,保存退出:
[Unit]

Description=Reboot Service

[Service]

Type=oneshot

ExecStart=/sbin/reboot

[Install]

WantedBy=multi-user.target

4、创建一个新的systemd定时器,这里创建的是reboot.timer:
touch /etc/systemd/system/reboot.timer

5、然后编辑文件:vi /etc/systemd/system/reboot.timer

6、在文件输入以下内容,保存退出:

[Unit]

Description=Reboot Timer

[Timer]

OnCalendar=*-*-* 09:00:00

[Install]

WantedBy=timers.target

注意:注意OnCalendar的:* * *09:00:00,其中第一个表示星期,第二个表示月份,第三个表示日期,后面的时间格式是小时:分钟:秒。

这里设置的是每天上午9点重启的。

7、启用并启动定时器:systemctl enable --now reboot.timer

设置完之后,就可以在每天的上午9点重启服务器了。