propellor/src/Propellor/Property/Reboot.hs

34 lines
969 B
Haskell
Raw Normal View History

2014-03-31 03:37:54 +00:00
module Propellor.Property.Reboot where
2014-03-31 03:55:59 +00:00
import Propellor
2014-12-06 17:21:19 +00:00
import Utility.SafeCommand
2014-12-06 17:32:53 +00:00
now :: Property
now = cmdProperty "reboot" []
`describe` "reboot now"
2014-12-06 17:21:19 +00:00
-- | 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 = []