major.io

Words of wisdom from a Linux engineer focused on information security

major.io

Words of wisdom from a systems engineer

  • Who am I?
  • icanhazip FAQ
  • Résumé
  • Keybase
  • RSS
Creative Commons License

Automatic package updates with dnf

May 11, 2015 By Major Hayden 19 Comments

12428002945_bc47ae3529_bWith Fedora 22’s release date quickly approaching, it’s time to familiarize yourself with dnf. It’s especially important since clean installs of Fedora 22 won’t have yum.

Almost all of the command line arguments are the same but automated updates are a little different. If you’re used to yum-updatesd, then you’ll want to look into dnf-automatic.

Installation

Getting the python code and systemd unit files for automated dnf updates is a quick process:

XHTML
1
dnf -y install dnf-automatic

Configuration

There’s only one configuration file to review and most of the defaults are quite sensible. Open up /etc/dnf/automatic.conf with your favorite text editor and review the available options. The only adjustment I made was to change the emit_via option to email as opposed to the stdio.

You may want to change the email_to option if you want to redirect email elsewhere. In my case, I already have an email forward for the root user.

dnf Automation

If you look at the contents of the dnf-automatic package, you’ll find some python code, configuration files, and two important systemd files:

For Fedora 25 and earlier:

XHTML
1
2
3
# rpm -ql dnf-automatic | grep systemd
/usr/lib/systemd/system/dnf-automatic.service
/usr/lib/systemd/system/dnf-automatic.timer

For Fedora 26 and later:

XHTML
1
2
3
4
5
6
7
# rpm -ql dnf-automatic | grep systemd
/usr/lib/systemd/system/dnf-automatic-download.service
/usr/lib/systemd/system/dnf-automatic-download.timer
/usr/lib/systemd/system/dnf-automatic-install.service
/usr/lib/systemd/system/dnf-automatic-install.timer
/usr/lib/systemd/system/dnf-automatic-notifyonly.service
/usr/lib/systemd/system/dnf-automatic-notifyonly.timer

These systemd files are what makes dnf-automatic run. The service file contains the instructions so that systemd knows what to run. The timer file contains the frequency of the update checks (defaults to one day). We need to enable the timer and then start it.

For Fedora 25 and earlier:

XHTML
1
systemctl enable dnf-automatic.timer

For Fedora 26 and later:

XHTML
1
systemctl enable dnf-automatic-install.timer

Check your work:

XHTML
1
2
3
# systemctl list-timers *dnf*
NEXT                         LEFT     LAST                         PASSED    UNIT                ACTIVATES
Tue 2015-05-12 19:57:30 CDT  23h left Mon 2015-05-11 19:57:29 CDT  14min ago dnf-automatic.timer dnf-automatic.service

The output here shows that the dnf-automatic job last ran at 19:57 on May 11th and it’s set to run at the same time tomorrow, May 12th. Be sure to disable and stop your yum-updatesd service if you still have it running on your system from a previous version of Fedora.

Photo Credit: Outer Rim Emperor via Compfight cc

Share this post:

  • Twitter
  • Google
  • LinkedIn
  • Reddit
  • Email
  • Print

Tagged With: dnf, fedora, python, systemd, yum

Comments

  1. Drajvergajd says

    May 15, 2015 at 11:31 pm

    Is it possible to configure it so it runs update twice on each run? I ask because I find out that when using akmods from rpmfusion, I have to redo the update process after the kernel gets updated so it can pull new kmods. Otherwise (when using NVIDIA driver) on next boot system doesn’t start X, and I have to manually drop to console and do an update and reboot.

    Reply
    • Major Hayden says

      May 18, 2015 at 6:11 am

      Hmm, you might be able to duplicate the timer that comes with dnf-automatic so that it runs at an offset, but that might not always work. Without some additional scripting, I’m not sure how to do that.

      Reply
      • Drajvergajd says

        May 18, 2015 at 3:03 pm

        Oh well, thanks anyway – it’s a great post.

        Reply
        • Major Hayden says

          May 19, 2015 at 6:21 am

          You’re welcome!

          Reply
      • Eric says

        August 2, 2015 at 9:40 pm

        You might be able to adjust the ExecStart command of /usr/lib/systemd/system/dnf-automatic.service to run the command twice in a row. Something like (which I haven’t tested):

        ExecStart=/usr/bin/dnf-automatic /etc/dnf/automatic.conf –timer && /usr/bin/dnf-automatic /etc/dnf/automatic.conf –timer

        Reply
  2. Nadim Kobeissi says

    May 17, 2015 at 10:40 pm

    Thanks, this is nice!

    Reply
    • Major Hayden says

      May 18, 2015 at 6:11 am

      Glad it helped!

      Reply
  3. Patrick Matthew Barahona says

    May 23, 2015 at 12:50 am

    When I checked the content of /etc/dnf/automatic.conf nothing was there. Would that be because I’m running MATE instead of GNOME 3 or is it supposed to show?

    Reply
    • Major Hayden says

      May 25, 2015 at 9:01 am

      Did you install the dnf-automatic package? That package has the automatic.conf file.

      Reply
      • Patrick Matthew Barahona says

        May 25, 2015 at 1:39 pm

        I already fixed it the same day I posted this post.

        Reply
  4. Aniruddha says

    May 27, 2015 at 8:02 am

    This a great feature! Do you happen to know if ‘upgrade_type = security’ also works with third party repositories such as rpmfusion and google chrome?

    Reply
    • Major Hayden says

      May 27, 2015 at 8:23 am

      As far as I know, it only works with Fedora repositories.

      Reply
      • Aniruddha says

        May 31, 2015 at 2:09 pm

        Thanks!

        Reply
  5. Marc Hollins says

    May 28, 2015 at 8:26 am

    Is there a way to set the time that dnf-automatic.timer will run? Mine is currently running at 4 PM, which is right when I’m trying to cram in a lot of work before the end of the day.

    Reply
    • Major Hayden says

      May 30, 2015 at 10:09 am

      You’ll probably need to patch the dnf-automatic.timer file and use OnCalandar. The Arch docs are helpful for that:

      https://wiki.archlinux.org/index.php/Systemd/Timers

      Don’t forget a systemd-reload afterwards.

      Reply
  6. Patrice B says

    August 13, 2015 at 8:49 am

    Thanks for this doc !

    Does it behave friendly with manual halt or reboot ? I mean, if rpms are installing, will the system wait before rebooting or shutting down ?

    Reply
  7. dnf-automatic-changed says

    August 25, 2017 at 11:20 pm

    Hello,
    Thanks for this page!

    In my experience dnf-automatic will now fail in Fedora 26+ as a change has been made where multiple systemd timers now exist for the service. See: https://fedoraproject.org/wiki/AutoUpdates#Changes_as_of_Fedora_26

    I’ve now enabled dnf-automatic-install.timer instead.

    Reply
    • Major Hayden says

      August 28, 2017 at 2:59 pm

      Good call. I’ll update the post.

      Reply
  8. Spongebob says

    January 12, 2018 at 1:30 pm

    (Fedora 27)

    You should start the timer too, right? Else, it won’t do anything until you reboot.

    # systemctl start dnf-automatic-install.timer

    Thanks for keeping this post updated.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.