diff options
| author | Joey Hess <id@joeyh.name> | 2014-12-06 13:21:19 -0400 |
|---|---|---|
| committer | Joey Hess <id@joeyh.name> | 2014-12-06 13:21:19 -0400 |
| commit | 29442f222ec2342c6dea7036e80e15eefa4158c0 (patch) | |
| tree | f29929e1d14f7aa8a7e8c662fcad237a3b7e143e /src/Propellor/Property/Reboot.hs | |
| parent | 62697c7b7f7ba2d39bfad632f1cf720c9805bdd2 (diff) | |
Reboot.atEnd
Diffstat (limited to 'src/Propellor/Property/Reboot.hs')
| -rw-r--r-- | src/Propellor/Property/Reboot.hs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/Propellor/Property/Reboot.hs b/src/Propellor/Property/Reboot.hs index 25e53159..3a725838 100644 --- a/src/Propellor/Property/Reboot.hs +++ b/src/Propellor/Property/Reboot.hs @@ -1,7 +1,29 @@ module Propellor.Property.Reboot where import Propellor +import Utility.SafeCommand -now :: Property -now = cmdProperty "reboot" [] - `describe` "reboot now" +-- | Schedules a reboot at the end of the current propellor run. +-- +-- The Result code of the endire propellor run can be checked; +-- the reboot proceeds only if the function returns True. +-- +-- The reboot can be forced to run, which bypasses the init system. Useful +-- if the init system might not be running for some reason. +atEnd :: Bool -> (Result -> Bool) -> Property +atEnd force resultok = property "scheduled reboot at end of propellor run" $ do + endAction "rebooting" atend + return NoChange + where + atend r + | resultok r = liftIO $ + ifM (boolSystem "reboot" rebootparams) + ( return MadeChange + , return FailedChange + ) + | otherwise = do + warningMessage "Not rebooting, due to status of propellor run." + return FailedChange + rebootparams + | force = [Param "--force"] + | otherwise = [] |
