propellor spin

This commit is contained in:
Joey Hess 2014-04-08 17:10:52 -04:00
parent c40fb997ed
commit 4ea2771b69
Failed to extract signature
3 changed files with 13 additions and 1 deletions

View File

@ -4,6 +4,7 @@ module Propellor.Property.Cmd (
scriptProperty, scriptProperty,
userScriptProperty, userScriptProperty,
serviceRunning, serviceRunning,
serviceRestarted,
) where ) where
import Control.Monad import Control.Monad
@ -47,13 +48,21 @@ userScriptProperty user script = cmdProperty "su" ["-c", shellcmd, user]
where where
shellcmd = intercalate " ; " ("set -e" : "cd" : script) shellcmd = intercalate " ; " ("set -e" : "cd" : script)
type ServiceName = String
-- | Ensures that a service is running. -- | Ensures that a service is running.
-- --
-- Note that due to the general poor state of init scripts, the best -- Note that due to the general poor state of init scripts, the best
-- we can do is try to start the service, and if it fails, assume -- we can do is try to start the service, and if it fails, assume
-- this means it's already running. -- this means it's already running.
serviceRunning :: String -> Property serviceRunning :: ServiceName -> Property
serviceRunning svc = Property ("running " ++ svc) $ do serviceRunning svc = Property ("running " ++ svc) $ do
void $ ensureProperty $ void $ ensureProperty $
scriptProperty ["service " ++ shellEscape svc ++ " start >/dev/null 2>&1 || true"] scriptProperty ["service " ++ shellEscape svc ++ " start >/dev/null 2>&1 || true"]
return NoChange return NoChange
serviceRestarted :: ServiceName -> Property
serviceRestarted svc = Property ("restarted " ++ svc) $ do
void $ ensureProperty $
scriptProperty ["service " ++ shellEscape svc ++ " restart >/dev/null 2>&1 || true"]
return NoChange

View File

@ -9,6 +9,8 @@ providerFor users = propertyList ("openid provider") $
[ serviceRunning "apache2" [ serviceRunning "apache2"
`requires` Apt.installed ["apache2"] `requires` Apt.installed ["apache2"]
, Apt.installed ["simpleid"] , Apt.installed ["simpleid"]
`onChange` serviceRestarted "apache2"
, serviceRestarted "apache2"
] ++ map identfile users ] ++ map identfile users
where where
identfile u = File.hasPrivContent $ concat identfile u = File.hasPrivContent $ concat

View File

@ -71,6 +71,7 @@ container _parenthost name
& serviceRunning "apache2" & serviceRunning "apache2"
`requires` Apt.installed ["apache2"] `requires` Apt.installed ["apache2"]
] ]
-- My own openid provider. Uses php, so containerized for security -- My own openid provider. Uses php, so containerized for security
-- and administrative sanity. -- and administrative sanity.
| name == "openid-provider" = Just $ Docker.containerFrom | name == "openid-provider" = Just $ Docker.containerFrom