type => 'string', pattern => '[0-9a-zA-Z. ]+',
default => '5min', optional => 1,
},
+ 'next-run' => {
+ description => "The date time of the next run, in server locale.",
+ type => 'string',
+ optional => 1,
+ },
unitfile => {
description => "unit file for the systemd.timer unit",
type => 'string', optional => 1,
use PVE::Tools qw(run_command file_set_contents file_get_contents trim dir_glob_foreach);
use PVE::Systemd;
-# systemd timer
+# note: not exactly cheap...
+my sub next_calendar_event {
+ my ($spec) = @_;
+
+ my $res = '-';
+ eval {
+ run_command(
+ ['systemd-analyze', 'calendar', $spec],
+ noerr => 1,
+ outfunc => sub {
+ my $line = shift;
+ if ($line =~ /^\s*Next elapse:\s*(.+)$/) {
+ $res = $1;
+ }
+ },
+ );
+ };
+ return $res;
+}
+
+# systemd timer, filter optionally by a $remote
sub get_schedules {
my ($filter_remote) = @_;
my $unitfile = "$systemd_dir/$filename";
my $unit = PVE::Systemd::read_ini($unitfile);
+ my $timer = $unit->{'Timer'};
push @$result, {
unitfile => $unitfile,
remote => $remote,
- schedule => $unit->{'Timer'}->{'OnCalendar'},
- delay => $unit->{'Timer'}->{'RandomizedDelaySec'},
+ schedule => $timer->{'OnCalendar'},
+ delay => $timer->{'RandomizedDelaySec'},
+ 'next-run' => next_calendar_event($timer->{'OnCalendar'}),
};
});
my $timer_unit_path = "/etc/systemd/system/$timer_unit";
# create systemd timer
- run_command(['systemd-analyze', 'calendar', $schedule], errmsg => "Invalid schedule specification", outfunc => sub {});
- run_command(['systemd-analyze', 'timespan', $delay], errmsg => "Invalid delay specification", outfunc => sub {});
+ run_command(
+ ['systemd-analyze', 'calendar', $schedule],
+ errmsg => "Invalid schedule specification",
+ outfunc => sub {},
+ );
+ run_command(
+ ['systemd-analyze', 'timespan', $delay],
+ errmsg => "Invalid delay specification",
+ outfunc => sub {},
+ );
my $timer = {
'Unit' => {
'Description' => "Timer for PBS Backup to remote $remote",