summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Reboot.hs
blob: c26286890c5a0e54b38b3708e8ad9adba5cce344 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 = []