Reboot.atEnd

This commit is contained in:
Joey Hess 2014-12-06 13:21:19 -04:00
parent 62697c7b7f
commit 29442f222e
6 changed files with 37 additions and 19 deletions

View File

@ -12,7 +12,6 @@ import qualified Propellor.Property.Cron as Cron
--import qualified Propellor.Property.Sudo as Sudo --import qualified Propellor.Property.Sudo as Sudo
import qualified Propellor.Property.User as User import qualified Propellor.Property.User as User
--import qualified Propellor.Property.Hostname as Hostname --import qualified Propellor.Property.Hostname as Hostname
--import qualified Propellor.Property.Reboot as Reboot
--import qualified Propellor.Property.Tor as Tor --import qualified Propellor.Property.Tor as Tor
import qualified Propellor.Property.Docker as Docker import qualified Propellor.Property.Docker as Docker

View File

@ -43,13 +43,13 @@ mainProperties host = do
-- are then also run. -- are then also run.
runPropellor :: Host -> Propellor Result -> IO Result runPropellor :: Host -> Propellor Result -> IO Result
runPropellor host a = do runPropellor host a = do
(ret, _s, endactions) <- runRWST (runWithHost a) host () (res, _s, endactions) <- runRWST (runWithHost a) host ()
endrets <- mapM (runEndAction host) endactions endres <- mapM (runEndAction host res) endactions
return $ mconcat (ret:endrets) return $ mconcat (res:endres)
runEndAction :: Host -> EndAction -> IO Result runEndAction :: Host -> Result -> EndAction -> IO Result
runEndAction host (EndAction desc a) = actionMessageOn (hostName host) desc $ do runEndAction host res (EndAction desc a) = actionMessageOn (hostName host) desc $ do
(ret, _s, _) <- runRWST (runWithHost (catchPropellor a)) host () (ret, _s, _) <- runRWST (runWithHost (catchPropellor (a res))) host ()
return ret return ret
-- | Ensures a list of Properties, with a display of each as it runs. -- | Ensures a list of Properties, with a display of each as it runs.

View File

@ -149,6 +149,5 @@ noChange :: Propellor Result
noChange = return NoChange noChange = return NoChange
-- | Registers an action that should be run at the very end, -- | Registers an action that should be run at the very end,
-- and only when all configured Properties of the host succeed. endAction :: Desc -> (Result -> Propellor Result) -> Propellor ()
endAction :: Desc -> Propellor Result -> Propellor ()
endAction desc a = tell [EndAction desc a] endAction desc a = tell [EndAction desc a]

View File

@ -11,6 +11,7 @@ import Propellor
import qualified Propellor.Property.Debootstrap as Debootstrap import qualified Propellor.Property.Debootstrap as Debootstrap
import qualified Propellor.Property.Ssh as Ssh import qualified Propellor.Property.Ssh as Ssh
import qualified Propellor.Property.File as File import qualified Propellor.Property.File as File
import qualified Propellor.Property.Reboot as Reboot
import Propellor.Property.Mount import Propellor.Property.Mount
import Propellor.Property.Chroot.Util (stdPATH) import Propellor.Property.Chroot.Util (stdPATH)
import Utility.SafeCommand import Utility.SafeCommand
@ -67,6 +68,8 @@ cleanInstallOnce confirmation = check (not <$> doesFileExist flagfile) $
go = go =
finalized finalized
`requires` `requires`
Reboot.atEnd True (/= FailedChange)
`requires`
propellorbootstrapped propellorbootstrapped
`requires` `requires`
flipped flipped
@ -137,11 +140,6 @@ cleanInstallOnce confirmation = check (not <$> doesFileExist flagfile) $
finalized = property "clean OS installed" $ do finalized = property "clean OS installed" $ do
liftIO $ writeFile flagfile "" liftIO $ writeFile flagfile ""
endAction "rebooting into new OS" $ liftIO $
ifM (boolSystem "reboot" [ Param "--force" ])
( return MadeChange
, return FailedChange
)
return MadeChange return MadeChange
flagfile = "/etc/propellor-cleaninstall" flagfile = "/etc/propellor-cleaninstall"

View File

@ -1,7 +1,29 @@
module Propellor.Property.Reboot where module Propellor.Property.Reboot where
import Propellor import Propellor
import Utility.SafeCommand
now :: Property -- | Schedules a reboot at the end of the current propellor run.
now = cmdProperty "reboot" [] --
`describe` "reboot now" -- 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 = []

View File

@ -204,5 +204,5 @@ fromVal NoVal = Nothing
type RunLog = [EndAction] type RunLog = [EndAction]
-- | An action that Propellor runs at the end, after trying to satisfy all -- | An action that Propellor runs at the end, after trying to satisfy all
-- properties. -- properties. It's passed the combined Result of the entire Propellor run.
data EndAction = EndAction Desc (Propellor Result) data EndAction = EndAction Desc (Result -> Propellor Result)