systemd timer で、定期的な処理をするちゃ
Catedral de Santa María de Toledo |
(1)定期的に処理するプログラムを作成する(いままで通り)
(2)(1)のプログラムのsystemdのserviceを作成する
(3)(2)を対象にした、systemdのtimerを作成する
(4)systemctlを使って有効にする。serviceは有効にしない。
だから、serviceには、[Install]を書かない
$ vi sysd-reboot.sh
#!/bin/bash
sudo /sbin/reboot
$vi sysd-reboot.service
[Unit]
Description=reboot
[Service]
Type=simple
ExecStart=/home/pi/bin/sysd-reboot.sh
$vi sysd-reboot.timer
[Unit]
Description=Run LDAP dump monthly
[Timer]
OnCalendar=*-*-* 04:00:00
Unit=sysd-reboot.service
[Install]
WantedBy=basic.target
$ sudo cp sysd-* /etc/systemd/system
$ sudo systemctl enable sysd-reboot.timer
Created symlink from /etc/systemd/system/basic.target.wants/sysd-reboot.timer to /etc/systemd/system/sysd-reboot.timer.
$ sudo systemctl start sysd-reboot.timer
(5)確認する
$ sudo systemctl list-unit-files --type=timer | grep sysd-
sysd-reboot.timer enabled
指定例)
[Unit]
Description=Run foo weekly and on boot
[Timer]
OnBootSec=15min
OnUnitActiveSec=1w
[Install]
WantedBy=timers.target
[Unit]
Description=Run foo weekly
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
usec, us
msec, ms
seconds, second, sec, s
minutes, minute, min, m
hours, hour, hr, h
days, day, d
weeks, week, w
months, month, M (defined as 30.44 days)
years, year, y (define as 365.25 days)
2 h 2hours 48hr 1y 12month 55s500ms 300ms20s 5day
Fri 2012-11-23 11:12:13 → Fri 2012-11-23 11:12:13 2012-11-23 11:12:13 → Fri 2012-11-23 11:12:13 2012-11-23 11:12:13 UTC → Fri 2012-11-23 19:12:13 2012-11-23 → Fri 2012-11-23 00:00:00 12-11-23 → Fri 2012-11-23 00:00:00 11:12:13 → Fri 2012-11-23 11:12:13 11:12:13.9900009 → Fri 2012-11-23 11:12:13 format_timestamp_us: Fri 2012-11-23 11:12:13.990000 11:12 → Fri 2012-11-23 11:12:00
now → Fri 2012-11-23 18:15:22
today → Fri 2012-11-23 00:00:00 today UTC → Fri 2012-11-23 16:00:00 yesterday → Fri 2012-11-22 00:00:00 tomorrow → Fri 2012-11-24 00:00:00 +3h30min → Fri 2012-11-23 21:45:22 +3h30min UTC → -EINVAL -5s → Fri 2012-11-23 18:15:17 11min ago → Fri 2012-11-23 18:04:22 11min ago UTC → -EINVAL @1395716396 → Tue 2014-03-25 03:59:56
参考)
systemd.time
0 件のコメント:
コメントを投稿