我有一个 systemd 模板,[email protected]
定义为:
[Unit]
Description=load script
Wants=network-online.target
After=network-online.target
PartOf=load.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 load -d %i
User=root
[Install]
WantedBy=default.target
我需要使用不同的参数运行此脚本的四个不同实例-d
,因此我将定义设置load.target
为:
[Unit]
Description=dataloader.load workers
[email protected] [email protected] [email protected] [email protected]
[Install]
WantedBy=multi-user.target
我希望这四个实例每 10 分钟运行一次。
如何设置 systemd 计时器以.target
按一定时间间隔调用?
答案1
您可以创建一个定时器单元,[email protected]
定义为:
[Unit]
Description=Run [email protected] every 10 minutes
[Timer]
OnCalendar=*:0/10
AccuracySec=1us
并修改load.target
为调用.timer
单位而不是.service
单位:
[Unit]
Description=dataloader.load workers
[email protected] [email protected] [email protected] [email protected]
[Install]
WantedBy=multi-user.target