Seasonal photo, (c) 2006 Christopher P. Lindsey, All Rights Reserved: do not copy

Scheduling a reboot via puppet after a kernel update with RHEL style distributions

I’ve had people ask me how to schedule a reboot of their system via puppet if a kernel upgrade was installed. I like to use the ‘at’ command


class yoursite::common::rebootforkernelchange {

   exec {'schedule-kernel-reboot':
      command => '/bin/echo "/usr/sbin/reboot" | at -m 4:00',
      path => '/usr/bin:/bin',
      unless => ['test `atq | wc -l` != 0', 'test `uname -r` = `rpm -q kernel --queryformat "%{RPMTAG_BUILDTIME} %{VERSION}-%{RELEASE}.%{ARCH}\n" | sort -nr | cut -d" " -f 2 | head -1`']
   }
}

This compares the current kernel against the latest built kernel that is installed, and if they don’t match it sets an at job to reboot the system at 4am.

If you want to check the latest installed kernel instead of the latest built kernel, change RPMTAG_BUILDTIME to RPMTAG_INSTALLTIME.