rfancn / aliyun-ddns-client

Python DDNS client for Aliyun
404 stars 137 forks source link

运用systemd的Timer文件定时运行ddns.py #14

Closed primovist closed 7 years ago

primovist commented 7 years ago

首先要有一个服务,可以起名ddns.service,内容如下: [Unit] Description=Aliyun DDNS Client. Wants=network-online.target After=network.target network-online.target

[Service] Type=simple WorkingDirectory=/root/tools/aliyun-ddns-client

这里写上你的aliyun-ddns-client文件夹地址,如果用我的范例请放入/root文件夹下

ExecStart=/usr/bin/python ddns.py

然后有个同名的Timer文件,ddns.timer,内容如下: [Unit] Description=Run Aliyun DDNS Client every 10 minutes.

[Timer] OnBootSec=0s OnUnitActiveSec=10min

这里可以改成你喜欢的时间

Unit=ddns.service

默认不写Unit时Timer文件运行同名Service,可以省略

[Install] WantedBy=multi-user.target

两个文件同时放入/usr/lib/systemd/system文件夹中,然后运行命令

systemctl daemon-reload

systemctl enable ddns.timer

可以查看状态:

systemctl status ddns.timer

rfancn commented 7 years ago

Thanks, merged to the master branch.