diff options
| author | Sean Whitton <spwhitton@spwhitton.name> | 2016-06-12 10:14:11 +0900 |
|---|---|---|
| committer | Sean Whitton <spwhitton@spwhitton.name> | 2016-06-12 10:14:11 +0900 |
| commit | 5e224ff3c0bf2bb8e47f0b024f8105555047dcb2 (patch) | |
| tree | 875a03d89528c5c65ac116bb1d4b12c1b349de39 /src/Propellor/Property/Reboot.hs | |
| parent | 655cb124a8db04361a60dee5e4e908f125c42e8b (diff) | |
toKernelNewerThan prop
Diffstat (limited to 'src/Propellor/Property/Reboot.hs')
| -rw-r--r-- | src/Propellor/Property/Reboot.hs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/Propellor/Property/Reboot.hs b/src/Propellor/Property/Reboot.hs index 343ee25b..41234489 100644 --- a/src/Propellor/Property/Reboot.hs +++ b/src/Propellor/Property/Reboot.hs @@ -8,6 +8,7 @@ module Propellor.Property.Reboot ( import Propellor.Base import Data.List +import Data.Version type KernelVersion = String @@ -49,13 +50,27 @@ toDistroKernel = check (not <$> runningInstalledKernel) now `describe` "running installed kernel" -- | Given a kernel version string @v@, reboots immediately if the running --- kernel version is strictly less than @v@ and the installed kernel version is --- greater than or equal to @v@ +-- kernel version is strictly less than @v@ and there is an installed kernel +-- version is greater than or equal to @v@ +-- +-- This assumes that the installed kernel with the highest version number is the +-- one that will be started if we reboot. -- -- This is useful when upgrading to a new version of Debian where you need to -- ensure that a new enough kernel is running before ensuring other properties. -toKernelNewerThan :: Version -> Property DebianLike -toKernelNewerThan v = undefined +toKernelNewerThan :: KernelVersion -> Property DebianLike +toKernelNewerThan ver = property' ("reboot to kernel newer than " ++ ver) $ \w -> + ifM (liftIO $ newerKernelAvailable (Prelude.read ver)) + (ensureProperty w now, noChange) + +newerKernelAvailable :: Version -> IO Bool +newerKernelAvailable wantV = do + runningV <- Prelude.read <$> runningKernelVersion + kernelImages <- installedKernelImages + when (null kernelImages) $ + error "failed to find any installed kernel images" + let installedV = maximum $ Prelude.read <$> kernelImages + return $ installedV >= wantV && runningV < wantV runningInstalledKernel :: IO Bool runningInstalledKernel = do |
