Bug 878826 - [rfe] dnf could use systemd timer unit rather than crontabs
[rfe] dnf could use systemd timer unit rather than crontabs
Status: CLOSED NEXTRELEASE
Product: Fedora
Classification: Fedora
Component: dnf (Show other bugs)
18
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Ales Kozumplik
Fedora Extras Quality Assurance
:
Depends On: 879597
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-21 05:35 EST by Harald Hoyer
Modified: 2014-09-30 19:40 EDT (History)
3 users (show)

See Also:
Fixed In Version: dnf-0.3.1
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-03-25 10:09:51 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Jochen Schmitt's patch for the RFE (3.40 KB, patch)
2013-01-22 03:44 EST, Ales Kozumplik
no flags Details | Diff

  None (edit)
Description Harald Hoyer 2012-11-21 05:35:38 EST
Instead of "/etc/cron.hourly/dnf-makecache.cron" and "/var/log/dnf-makecache.cron", I would suggest to use systemd timer units and make use of the logging features of systemd.

This way we do not require cron and we can deinstall it.

$ sudo rpm -e cronie cronie-anacron crontabs
error: Failed dependencies:
	crontabs is needed by (installed) dnf-0.2.15-3.git5d85f6b.fc18.noarch

dnf is the only rpm needing crontabs on my system with 2142 rpm packages installed.

$ rpm -qa | wc -l
2142


$ cat /usr/lib/systemd/system/dnf-makecache.timer
[Unit]
Description=dnf makecache timer

[Timer]
OnBootSec=10min
OnUnitInactiveSec=1h
Unit=dnf-makecache.service

[Install]
WantedBy=basic.target

$ cat /usr/lib/systemd/system/dnf-makecache.service
[Unit]
Description=dnf makecache

[Service]
Type=oneshot
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStart=/usr/bin/dnf makecache
Comment 1 Harald Hoyer 2012-11-21 05:40:56 EST
$ systemctl status dnf-makecache.timer  
dnf-makecache.timer - dnf makecache timer
	  Loaded: loaded (/etc/systemd/system/dnf-makecache.timer; disabled)
	  Active: active (waiting) since Wed, 2012-11-21 11:31:10 CET; 6min ago

$ systemctl status dnf-makecache.service
dnf-makecache.service - dnf makecache
	  Loaded: loaded (/etc/systemd/system/dnf-makecache.service; static)
	  Active: inactive (dead) since Wed, 2012-11-21 11:30:10 CET; 8min ago
	Main PID: 3779 (code=exited, status=0/SUCCESS)
	  CGroup: name=systemd:/system/dnf-makecache.service

Nov 21 11:30:09 lenovo systemd[1]: Starting dnf makecache...
Nov 21 11:30:10 lenovo dnf[3779]: Metadata Cache Created
Nov 21 11:30:10 lenovo systemd[1]: Started dnf makecache.

$ sudo journalctl _SYSTEMD_UNIT=dnf-makecache.service
-- Logs begin at Thu, 2012-07-19 10:37:56 CEST, end at Mon, 2012-09-10 11:09:10 CEST. --
Nov 21 09:30:10 lenovo dnf[3761]: Metadata Cache Created
Nov 21 10:30:10 lenovo dnf[3772]: Metadata Cache Created
Nov 21 11:30:10 lenovo dnf[3779]: Metadata Cache Created
Comment 2 Ales Kozumplik 2012-11-21 07:14:07 EST
Hi Harald, thanks for the report, I had no idea that this is how the repeating tasks are done now. I've got quite a lot of things to do on DNF right now, so your patch helps a lot. One question:

[Timer]
OnBootSec=10min
OnUnitInactiveSec=1h
Unit=dnf-makecache.service

Does this mean that makecache will run 10 minutes after every boot and then every hour?

Also (and I have been wondering about how to do this for some time): could there be a timer item to specify the required network service level, e.g.:

[Timer]
...
NetworkServiceAtLeast=Ethernet

Because if people are connected via their crazy expensive 3G (and NetworkManager should have this information) I can imagine they are not cool about package manager updating itself every hour.
Comment 3 Harald Hoyer 2012-11-21 08:22:21 EST
(In reply to comment #2)
> Hi Harald, thanks for the report, I had no idea that this is how the
> repeating tasks are done now. I've got quite a lot of things to do on DNF
> right now, so your patch helps a lot. One question:
> 
> [Timer]
> OnBootSec=10min
> OnUnitInactiveSec=1h
> Unit=dnf-makecache.service
> 
> Does this mean that makecache will run 10 minutes after every boot and then
> every hour?

yes

$ man systemd.timer
OnBootSec= defines a timer relative to when the machine was
           booted up.

> 
> Also (and I have been wondering about how to do this for some time): could
> there be a timer item to specify the required network service level, e.g.:
> 
> [Timer]
> ...
> NetworkServiceAtLeast=Ethernet
> 
> Because if people are connected via their crazy expensive 3G (and
> NetworkManager should have this information) I can imagine they are not cool
> about package manager updating itself every hour.

Well, this has to be resolved via other mechanisms than systemd. systemd does not know the current network state.

Maybe this cache polling should be removed entirely?
Comment 4 Ales Kozumplik 2012-11-23 07:35:06 EST
> Well, this has to be resolved via other mechanisms than systemd. systemd
> does not know the current network state.
> 
> Maybe this cache polling should be removed entirely?

I don't think it would be a good thing to start dropping components' functionalities just to make them fit into the systemd's scheme of things.
Comment 5 Harald Hoyer 2012-11-23 08:41:41 EST
(In reply to comment #4)
> > Well, this has to be resolved via other mechanisms than systemd. systemd
> > does not know the current network state.
> > 
> > Maybe this cache polling should be removed entirely?
> 
> I don't think it would be a good thing to start dropping components'
> functionalities just to make them fit into the systemd's scheme of things.

Well, the dropping suggestions was not based on systemd's functionality but your own argument "if people are connected via their crazy expensive 3G".

Even NetworkManager cannot know, if your laptop is connected to your mobile hotspot via WLAN.
Comment 6 Ales Kozumplik 2012-11-23 08:50:18 EST
(In reply to comment #5)
> Even NetworkManager cannot know, if your laptop is connected to your mobile
> hotspot via WLAN.

Easy, add a checkbox in the NM WLAN dialog that says 'Minimize maintenance traffic through this network.' We'll need it anyway at some point---for instance most other synchronization tasks like backups.

I opened the systemd bug 879370 for this.
Comment 7 Ales Kozumplik 2013-01-07 02:56:13 EST
Related: bug 878826.
Comment 8 Ales Kozumplik 2013-01-22 03:44:57 EST
Created attachment 684945 [details]
Jochen Schmitt's patch for the RFE
Comment 9 Ales Kozumplik 2013-03-25 10:09:51 EDT
Addressed by commit 878826, will be included in dnf-0.3.1.

The cron file stays in the repo but only the systemd .timer file is packaged for Fedora. The custom ABRT collector stays broken, bug 879597.
Comment 10 Marcos Mello 2013-08-30 22:26:32 EDT
Nit: the "Unit=" line is optional in the .timer file if it has the same basename of the .service.

"For each timer file, a matching unit file must exist, describing the unit to activate when the timer elapses. By default, a service by the same name as the timer (except for the suffix) is activated. Example: a timer file foo.timer activates a matching service foo.service. The unit to activate may be controlled by Unit= (see below)."

http://www.freedesktop.org/software/systemd/man/systemd.timer.html
Comment 11 Ales Kozumplik 2013-09-02 02:11:58 EDT
Hi Marcos, if you prefer the service file without the Unit= line please open a new bugzilla, this one has been long closed. Thank you.

Note You need to log in before you can comment on or make changes to this bug.