rthomsen / kcmsystemd

A systemd control module for KDE
GNU General Public License v3.0
53 stars 5 forks source link

RFE: add a tab that mimics systemctl list-timers --all #13

Closed a-detiste closed 9 years ago

a-detiste commented 9 years ago

I propose to help on this; users with only systemd-tmpfiles-clean.timer wouldn't care about this.

I know the timer units are already listed in the Units tab, but this would allow for special handling of timers.

I also plan to make a plasmoid that display the upcoming events.

NEXT                         LEFT         LAST                         PASSED             UNIT                         ACTIVAT
mar 2015-02-24 16:00:00 CET  39min left   mar 2015-02-24 15:00:03 CET  20min ago          cron-hourly.timer            cron-ho
mar 2015-02-24 18:26:13 CET  3h 5min left lun 2015-02-23 18:26:13 CET  20h ago            systemd-tmpfiles-clean.timer systemd
mer 2015-02-25 06:17:00 CET  14h left     mar 2015-02-24 06:17:13 CET  9h ago             cron-daily.timer             cron-da
dim 2015-03-01 00:00:00 CET  4 days left  dim 2015-02-01 00:00:02 CET  3 weeks 2 days ago cron-monthly.timer           cron-mo
lun 2015-03-02 00:00:00 CET  5 days left  lun 2015-02-23 00:00:03 CET  1 day 15h ago      cron-weekly.timer            cron-we
n/a                          n/a          n/a                          n/a                systemd-readahead-done.timer systemd

6 timers listed.
rthomsen commented 9 years ago

This should be possible through the DBus api. I will investigate...

a-detiste commented 9 years ago

For reference:

static int list_timers(sd_bus *bus, char **args)

https://github.com/systemd/systemd/blob/95d383ee47db488f182048cfd6846f2e6b859f2b/src/systemctl/systemctl.c#L1157

static int output_timers_list(struct timer_info *timer_infos, unsigned n)

https://github.com/systemd/systemd/blob/95d383ee47db488f182048cfd6846f2e6b859f2b/src/systemctl/systemctl.c#L1028

rthomsen commented 9 years ago

I have started to implement this. The next elapse of a timer can be fetched through dbus using the NextElapseUSecMonotonic property for monotonic timers and NextElapseUSecRealtime for calendar timers. However, the output of systemctl list-timers is not consistent with what I fetch through dbus and what is specified in the unit file. The only timer unit I have is systemd-tmpfiles-clean.timer and for that timer systemctl outputs:

NEXT                         LEFT    LAST                         PASSED       UNIT                         ACTIVATES
Fri 2015-03-06 04:38:57 CET  9h left Wed 2015-03-04 13:35:29 CET  1 day 5h ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service

According to the unit file this timer should be activated 15min after boot and then every 24h. So NEXT should always be exactly 24h after LAST, and that is also what I fetch through dbus.

Do you experience the same on your system?

a-detiste commented 9 years ago

If you are using a laptop with suspend, the OnUnitActiveSec=1d timer stops counting time when the PC is off.

rthomsen commented 9 years ago

Ah ok, that would explain it. Thanks. Then we need to figure out how to find the total time the system has been suspended and add that to the values fetched through dbus...

a-detiste commented 9 years ago

get_next_elapse() gets the raw data, then they are reprocessed thourgh calc_next_elapse() I would have been easier (better ?) for you if all these computations were on the other side of the Dbus; now you'd have to re-implement everything :-( or maybe some of this code could be shared in libsystemd .

rthomsen commented 9 years ago

See a80cbdc2e25b8f8e34376ee605dcb89f1a2ff32b

Currently only supports monotonic timers. Can you test if your timer units display the correct NEXT and LAST.

a-detiste commented 9 years ago

systemd-tmpfiles-clean.timer is OK.

for the rest LAST is missing if timer has not elapsed since last boot; NEXT is allways set to system boot time

timers

rthomsen commented 9 years ago

How are the cron timers set up, i.e. which of the OnActiveSec, OnBootSec, OnStartupSec, OnUnitActiveSec, OnUnitInactiveSec and OnCalendar settings do they use in their unit files? And what are the values?

a-detiste commented 9 years ago

they are all setup this way, with OnCalendar=hourly|daily|weekly|monthly; to get anacron-like behaviour

[Timer]
Persistent=true
OnCalendar=

*(well cron-daily.timer is overiden to start at 6h17 )


cron-php5-root-0.timer is dynamicaly translated from this:

# Look for and purge old sessions every 30 minutes                                                                            
09,39 *     * * *     root   [ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean

to this: OnCalendar=*-*-* *:9,39:00

https://github.com/systemd-cron/systemd-cron

rthomsen commented 9 years ago

With 8da3289baa7066809a36262a2e034001daf96e15, calendar-based timers display next and past time points correctly on my system now. Can you test?

a-detiste commented 9 years ago

:smile: impressive !

only bit missing is last execution of Persistent=true task that ran last monday & last first day of month

a-detiste commented 9 years ago

LastTriggerUSec

a-detiste commented 9 years ago

https://github.com/a-detiste/kcmsystemd/commit/9b6fd8b163dd870182ab14f4d850a2f4c092ec68

timers_next

a-detiste commented 9 years ago

systemctl sortby Next column

rthomsen commented 9 years ago

Commited in eb700ae02468e635a550ab439200f9fa3c7ed4d8

Nice catch finding the undocumented LastTriggerUSec property ;)

rthomsen commented 9 years ago

@a-detiste I added user timers to the timers tab. As you suggested I used an icon to differentiate between user and system timers. What do you think? :)

a-detiste commented 9 years ago

it's nice; but I don't grasp the icon choice for system units QIcon::fromTheme("object-locked"); why not use somme standard gear icon ?

rthomsen commented 9 years ago

I actually tried to find a gear, but couldn't find one in the breeze icon set...

a-detiste commented 9 years ago

It's called applications-system , but in Breeze it is replaced by some dots/electrons thing

Oxygen

applications-system

breeze

breeze

Adwaita

applications-system

mono

mono

rthomsen commented 9 years ago

Ok, I guess the levers make more sense than a padlock. I will change it...

a-detiste commented 9 years ago

indeed, it's now ok in the quickgit repo

so this issue & #17 are done and can be closed ?

rthomsen commented 9 years ago

Yeah, I think we can close this issue now. I want to implement some right-click actions for the timers, but I'm busy with other things right now...