From e2ea89aa7a5da2d239fe46d036dfc7fa92e56a03 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Mon, 31 Aug 2015 19:55:17 +0000 Subject: [PATCH 1/6] reboot_required_notify: move all code to a ::wheezy class. It doesn't work on Jessie and newer (#1). --- manifests/reboot_required_notify.pp | 18 +----------------- manifests/reboot_required_notify/wheezy.pp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 manifests/reboot_required_notify/wheezy.pp diff --git a/manifests/reboot_required_notify.pp b/manifests/reboot_required_notify.pp index 722e8a5..d0006f3 100644 --- a/manifests/reboot_required_notify.pp +++ b/manifests/reboot_required_notify.pp @@ -1,21 +1,5 @@ class apt::reboot_required_notify { - # This package installs the script that created /var/run/reboot-required*. - # This script (/usr/share/update-notifier/notify-reboot-required) is - # triggered e.g. by kernel packages. - package { 'update-notifier-common': - ensure => installed, - } - - # cron-apt defaults to run every night at 4 o'clock - # plus some random time <1h. - # so we check if a reboot is required a bit later. - cron { 'apt_reboot_required_notify': - command => 'if [ -f /var/run/reboot-required ]; then echo "Reboot required\n" ; cat /var/run/reboot-required.pkgs ; fi', - user => root, - hour => 5, - minute => 20, - require => Package['update-notifier-common'], - } + class { 'apt::reboot_required_notify::wheezy': } } diff --git a/manifests/reboot_required_notify/wheezy.pp b/manifests/reboot_required_notify/wheezy.pp new file mode 100644 index 0000000..14fdd79 --- /dev/null +++ b/manifests/reboot_required_notify/wheezy.pp @@ -0,0 +1,22 @@ +class apt::reboot_required_notify::wheezy { + + # On Wheezy and older, this package installs the script that created + # /var/run/reboot-required*. + # This script (/usr/share/update-notifier/notify-reboot-required) is + # triggered e.g. by kernel packages. + package { 'update-notifier-common': + ensure => installed, + } + + # cron-apt defaults to run every night at 4 o'clock + # plus some random time <1h. + # so we check if a reboot is required a bit later. + cron { 'apt_reboot_required_notify': + command => 'if [ -f /var/run/reboot-required ]; then echo "Reboot required\n" ; cat /var/run/reboot-required.pkgs ; fi', + user => root, + hour => 5, + minute => 20, + require => Package['update-notifier-common'], + } + +} From a82e3ae272c8510b3dc30f499316a7bfb518d330 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Mon, 31 Aug 2015 19:56:16 +0000 Subject: [PATCH 2/6] reboot_required_notify::wheezy: add an "ensure" parameter, defaulting to "present". --- manifests/reboot_required_notify/wheezy.pp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/manifests/reboot_required_notify/wheezy.pp b/manifests/reboot_required_notify/wheezy.pp index 14fdd79..06998ef 100644 --- a/manifests/reboot_required_notify/wheezy.pp +++ b/manifests/reboot_required_notify/wheezy.pp @@ -1,17 +1,18 @@ -class apt::reboot_required_notify::wheezy { +class apt::reboot_required_notify::wheezy ($ensure = present) { # On Wheezy and older, this package installs the script that created # /var/run/reboot-required*. # This script (/usr/share/update-notifier/notify-reboot-required) is # triggered e.g. by kernel packages. package { 'update-notifier-common': - ensure => installed, + ensure => $ensure, } # cron-apt defaults to run every night at 4 o'clock # plus some random time <1h. # so we check if a reboot is required a bit later. cron { 'apt_reboot_required_notify': + ensure => $ensure, command => 'if [ -f /var/run/reboot-required ]; then echo "Reboot required\n" ; cat /var/run/reboot-required.pkgs ; fi', user => root, hour => 5, From 3630285006d9fb60c5fbecebc976623c37dd1395 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Mon, 31 Aug 2015 20:01:22 +0000 Subject: [PATCH 3/6] reboot_required_notify: add initial support for Jessie and newer. Note that reboot-notifier is only in stretch/sid at the moment, so to use this one needs to configure APT pinning themselves to make this package installable. --- manifests/reboot_required_notify.pp | 15 ++++++++++++++- manifests/reboot_required_notify/jessie.pp | 13 +++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 manifests/reboot_required_notify/jessie.pp diff --git a/manifests/reboot_required_notify.pp b/manifests/reboot_required_notify.pp index d0006f3..82466d2 100644 --- a/manifests/reboot_required_notify.pp +++ b/manifests/reboot_required_notify.pp @@ -1,5 +1,18 @@ class apt::reboot_required_notify { - class { 'apt::reboot_required_notify::wheezy': } + $jessie_or_newer = $::operatingsystemmajrelease ? { + 5 => false, + 6 => false, + 7 => false, + default => true, + } + + if $jessie_or_newer { + class { 'apt::reboot_required_notify::jessie': } + # Clean up systems that were upgraded from Wheezy or earlier: + class { 'apt::reboot_required_notify::wheezy': ensure => absent } + } else { + class { 'apt::reboot_required_notify::wheezy': } + } } diff --git a/manifests/reboot_required_notify/jessie.pp b/manifests/reboot_required_notify/jessie.pp new file mode 100644 index 0000000..51b75a2 --- /dev/null +++ b/manifests/reboot_required_notify/jessie.pp @@ -0,0 +1,13 @@ +class apt::reboot_required_notify::jessie ($ensure = present) { + + # On Jessie and newer, this package installs the script that created + # /var/run/reboot-required*. + # This script (/usr/share/update-notifier/notify-reboot-required) is + # triggered e.g. by kernel packages. + # This package also sends a daily email to the administrator when a system + # reboot is required, e.g. due to a kernel update. + package { 'reboot-notifier': + ensure => $ensure, + } + +} From e70a6712d31e91ecbf71f4de841735c3b36193ba Mon Sep 17 00:00:00 2001 From: intrigeri Date: Wed, 16 Mar 2016 14:26:52 +0000 Subject: [PATCH 4/6] apt::reboot_required_notify::jessie: manage APT pinning to fetch reboot-notifier from jessie-backports, when running on Jessie. --- manifests/reboot_required_notify/jessie.pp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/manifests/reboot_required_notify/jessie.pp b/manifests/reboot_required_notify/jessie.pp index 51b75a2..9b5a0c0 100644 --- a/manifests/reboot_required_notify/jessie.pp +++ b/manifests/reboot_required_notify/jessie.pp @@ -1,5 +1,15 @@ class apt::reboot_required_notify::jessie ($ensure = present) { + $pinning_ensure = $::operatingsystemmajrelease ? { + 8 => present, + default => absent, + } + apt::preferences_snippet { 'reboot-notifier': + ensure => $pinning_ensure, + pin => 'release o=Debian Backports,a=jessie-backports', + priority => 991, + } + # On Jessie and newer, this package installs the script that created # /var/run/reboot-required*. # This script (/usr/share/update-notifier/notify-reboot-required) is @@ -7,7 +17,8 @@ class apt::reboot_required_notify::jessie ($ensure = present) { # This package also sends a daily email to the administrator when a system # reboot is required, e.g. due to a kernel update. package { 'reboot-notifier': - ensure => $ensure, + ensure => $ensure, + require => Apt::Preferences_snippet['reboot-notifier'], } - + } From 89a024678e39fec8a5c05371bcceaece605fbd88 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Wed, 29 Jun 2016 17:54:16 +0000 Subject: [PATCH 5/6] apt::reboot_required_notify::jessie: explicitly check that $apt::use_backports is true when running Jessie. Otherwise, it would fail anyway when trying to install reboot-notifier, but in a way less user-friendly. Thanks to lavamind for the suggestion! --- manifests/reboot_required_notify/jessie.pp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/manifests/reboot_required_notify/jessie.pp b/manifests/reboot_required_notify/jessie.pp index 9b5a0c0..2de6b62 100644 --- a/manifests/reboot_required_notify/jessie.pp +++ b/manifests/reboot_required_notify/jessie.pp @@ -1,5 +1,9 @@ class apt::reboot_required_notify::jessie ($ensure = present) { + if $::operatingsystemmajrelease == 8 and ! $::apt::use_backports { + fail('apt::reboot_required_notify requires $apt::use_backports on Jessie') + } + $pinning_ensure = $::operatingsystemmajrelease ? { 8 => present, default => absent, From 70118955f6dae59a021880865408cf9367c3dc57 Mon Sep 17 00:00:00 2001 From: intrigeri Date: Wed, 29 Jun 2016 17:56:40 +0000 Subject: [PATCH 6/6] apt::reboot_required_notify: get rid of temporary variable. --- manifests/reboot_required_notify.pp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/manifests/reboot_required_notify.pp b/manifests/reboot_required_notify.pp index 82466d2..efd8aeb 100644 --- a/manifests/reboot_required_notify.pp +++ b/manifests/reboot_required_notify.pp @@ -1,13 +1,6 @@ class apt::reboot_required_notify { - $jessie_or_newer = $::operatingsystemmajrelease ? { - 5 => false, - 6 => false, - 7 => false, - default => true, - } - - if $jessie_or_newer { + if versioncmp($::operatingsystemmajrelease, 8) >= 0 { class { 'apt::reboot_required_notify::jessie': } # Clean up systems that were upgraded from Wheezy or earlier: class { 'apt::reboot_required_notify::wheezy': ensure => absent }