use Daemon.restarted consistently, and implement using Service.restarted

This commit is contained in:
Joey Hess 2014-09-23 13:19:26 -04:00
parent 28a966e4b5
commit f6ac681da0
3 changed files with 14 additions and 12 deletions

View File

@ -54,7 +54,7 @@ installed :: Property
installed = Apt.installed ["apache2"] installed = Apt.installed ["apache2"]
restarted :: Property restarted :: Property
restarted = cmdProperty "service" ["apache2", "restart"] restarted = Service.restarted "apache2"
reloaded :: Property reloaded :: Property
reloaded = Service.reloaded "apache2" reloaded = Service.reloaded "apache2"

View File

@ -3,7 +3,7 @@ module Propellor.Property.Ssh (
permitRootLogin, permitRootLogin,
passwordAuthentication, passwordAuthentication,
hasAuthorizedKeys, hasAuthorizedKeys,
restartSshd, restarted,
randomHostKeys, randomHostKeys,
hostKeys, hostKeys,
hostKey, hostKey,
@ -15,6 +15,7 @@ module Propellor.Property.Ssh (
import Propellor import Propellor
import qualified Propellor.Property.File as File import qualified Propellor.Property.File as File
import qualified Propellor.Property.Service as Service
import Propellor.Property.User import Propellor.Property.User
import Utility.SafeCommand import Utility.SafeCommand
import Utility.FileMode import Utility.FileMode
@ -33,7 +34,7 @@ setSshdConfig setting allowed = combineProperties "sshd config"
[ sshdConfig `File.lacksLine` (sshline $ not allowed) [ sshdConfig `File.lacksLine` (sshline $ not allowed)
, sshdConfig `File.containsLine` (sshline allowed) , sshdConfig `File.containsLine` (sshline allowed)
] ]
`onChange` restartSshd `onChange` restarted
`describe` unwords [ "ssh config:", setting, sshBool allowed ] `describe` unwords [ "ssh config:", setting, sshBool allowed ]
where where
sshline v = setting ++ " " ++ sshBool v sshline v = setting ++ " " ++ sshBool v
@ -59,15 +60,15 @@ hasAuthorizedKeys = go <=< dotFile "authorized_keys"
where where
go f = not . null <$> catchDefaultIO "" (readFile f) go f = not . null <$> catchDefaultIO "" (readFile f)
restartSshd :: Property restarted :: Property
restartSshd = cmdProperty "service" ["ssh", "restart"] restarted = Service.restarted "ssh"
-- | Blows away existing host keys and make new ones. -- | Blows away existing host keys and make new ones.
-- Useful for systems installed from an image that might reuse host keys. -- Useful for systems installed from an image that might reuse host keys.
-- A flag file is used to only ever do this once. -- A flag file is used to only ever do this once.
randomHostKeys :: Property randomHostKeys :: Property
randomHostKeys = flagFile prop "/etc/ssh/.unique_host_keys" randomHostKeys = flagFile prop "/etc/ssh/.unique_host_keys"
`onChange` restartSshd `onChange` restarted
where where
prop = property "ssh random host keys" $ do prop = property "ssh random host keys" $ do
void $ liftIO $ boolSystem "sh" void $ liftIO $ boolSystem "sh"
@ -91,7 +92,7 @@ hostKey keytype context = combineProperties desc
[ installkey (SshPubKey keytype "") (install writeFile ".pub") [ installkey (SshPubKey keytype "") (install writeFile ".pub")
, installkey (SshPrivKey keytype "") (install writeFileProtected "") , installkey (SshPrivKey keytype "") (install writeFileProtected "")
] ]
`onChange` restartSshd `onChange` restarted
where where
desc = "known ssh host key (" ++ fromKeyType keytype ++ ")" desc = "known ssh host key (" ++ fromKeyType keytype ++ ")"
installkey p a = withPrivData p context $ \getkey -> installkey p a = withPrivData p context $ \getkey ->
@ -176,7 +177,7 @@ listenPort port = RevertableProperty enable disable
portline = "Port " ++ show port portline = "Port " ++ show port
enable = sshdConfig `File.containsLine` portline enable = sshdConfig `File.containsLine` portline
`describe` ("ssh listening on " ++ portline) `describe` ("ssh listening on " ++ portline)
`onChange` restartSshd `onChange` restarted
disable = sshdConfig `File.lacksLine` portline disable = sshdConfig `File.lacksLine` portline
`describe` ("ssh not listening on " ++ portline) `describe` ("ssh not listening on " ++ portline)
`onChange` restartSshd `onChange` restarted

View File

@ -3,6 +3,7 @@ module Propellor.Property.Tor where
import Propellor import Propellor
import qualified Propellor.Property.File as File import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service
isBridge :: Property isBridge :: Property
isBridge = setup `requires` Apt.installed ["tor"] isBridge = setup `requires` Apt.installed ["tor"]
@ -13,7 +14,7 @@ isBridge = setup `requires` Apt.installed ["tor"]
, "ORPort 443" , "ORPort 443"
, "BridgeRelay 1" , "BridgeRelay 1"
, "Exitpolicy reject *:*" , "Exitpolicy reject *:*"
] `onChange` restartTor ] `onChange` restarted
restartTor :: Property restarted :: Property
restartTor = cmdProperty "service" ["tor", "restart"] restarted = Service.restarted "tor"