summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Reboot.hs
diff options
context:
space:
mode:
authorJoey Hess2014-12-07 12:04:58 -0400
committerJoey Hess2014-12-07 12:04:58 -0400
commit322ae878bbaef94736fdc4cae60b6c3b8c17a54d (patch)
tree4113593f21d964ad8f821ebbd408a528011f1398 /src/Propellor/Property/Reboot.hs
parentb7da90a91516c0d496c44459ed03009e58f39233 (diff)
parentdd40a05ced3b7c50a3a7751c66ad5a253056459e (diff)
Merge branch 'joeyconfig'
Conflicts: privdata.joey/privdata.gpg
Diffstat (limited to 'src/Propellor/Property/Reboot.hs')
-rw-r--r--src/Propellor/Property/Reboot.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/Propellor/Property/Reboot.hs b/src/Propellor/Property/Reboot.hs
index 25e53159..c2628689 100644
--- a/src/Propellor/Property/Reboot.hs
+++ b/src/Propellor/Property/Reboot.hs
@@ -1,7 +1,33 @@
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 = []