systemctl 启动类似 cron 的作业

systemctl 启动类似 cron 的作业

/etc/systemd/system目录中我有:

rsnapshot-backup.service文件,内容如下:

[Unit]
Description=rsnapshot backup automation [cron like]

[Service]
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStart=/usr/bin/notify-send "Rsnapshot Hourly Backup In Progress"

rsnapshot-backup.timer文件,内容如下:

[Unit]
Description=hourly rsnapshot backup

[Timer]
OnCalendar=*-*-* *:43:00
Persistent=true

[Install]
WantedBy=timers.target

但我没看到notify-send被触发?可能出了什么问题?

systemctl list-timers给出:

NEXT                          LEFT          LAST           PASSED                  UNIT                         ACTIVATES
Sat 2014-08-16 09:43:00 CEST  2min 37s left Sat 2014-08-16 09:31:18 CEST  9min ago rsnapshot-backup.timer       rsnapshot-backup.service

systemctl status rsnapshot-backup.service给出:

● rsnapshot-backup.service - rsnapshot backup automation [cron like]
    Loaded: loaded (/etc/systemd/system/rsnapshot-backup.service; static)
    Active: inactive (dead) since Sat 2014-08-16 09:31:21 CEST; 11min ago
    Process: 228 ExecStart=/usr/bin/notify-send Rsnapshot Hourly Backup In Progress (code=exited, status=0/SUCCESS)
    Main PID: 228 (code=exited, status=0/SUCCESS)

systemctl status rsnapshot-backup.timer给出:

● rsnapshot-backup.timer - hourly rsnapshot backup
    Loaded: loaded (/etc/systemd/system/rsnapshot-backup.timer; enabled)
    Active: active (waiting) since Sat 2014-08-16 09:31:16 CEST; 12min ago

编辑 这样做journalctl -u rsnapshot-backup,我可以确认服务已成功启动,但是没有显示任何内容(通知发送)。

-- Reboot --
Aug 16 09:43:14 ----------------- systemd[1]: Starting rsnapshot backup automation [cron like]...
Aug 16 09:43:14 ----------------- systemd[1]: Started rsnapshot backup automation [cron like].
Aug 16 10:00:06 ----------------- systemd[1]: Starting rsnapshot backup automation [cron like]...
Aug 16 10:00:07 ----------------- systemd[1]: Started rsnapshot backup automation [cron like].
Aug 16 10:19:04 ----------------- systemd[1]: Starting rsnapshot backup automation [cron like]...
Aug 16 10:19:04 ----------------- systemd[1]: Started rsnapshot backup automation [cron like].

相关内容