serviceInstalledRunning

This commit is contained in:
Joey Hess 2014-04-08 19:31:03 -04:00
parent 7561ee0443
commit a52a2a89df
8 changed files with 41 additions and 36 deletions

View File

@ -8,6 +8,7 @@ import Control.Monad
import Propellor
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Service as Service
import Propellor.Property.File (Line)
sourcesList :: FilePath
@ -149,9 +150,7 @@ autoRemove = runApt ["-y", "autoremove"]
unattendedUpgrades :: RevertableProperty
unattendedUpgrades = RevertableProperty enable disable
where
enable = setup True
`before` installed ["cron"]
`before` serviceRunning "cron"
enable = setup True `before` Service.running "cron"
disable = setup False
setup enabled = (if enabled then installed else removed) ["unattended-upgrades"]
@ -176,3 +175,10 @@ reConfigure package vals = reconfigure `requires` setselections
hPutStrLn h $ unwords [package, template, tmpltype, value]
hClose h
reconfigure = cmdProperty "dpkg-reconfigure" ["-fnone", package]
-- | Ensures that a service is installed and running.
--
-- Assumes that there is a 1:1 mapping between service names and apt
-- package names.
serviceInstalledRunning :: Package -> Property
serviceInstalledRunning svc = Service.running svc `requires` installed [svc]

View File

@ -3,16 +3,12 @@ module Propellor.Property.Cmd (
cmdProperty',
scriptProperty,
userScriptProperty,
serviceRunning,
serviceRestarted,
) where
import Control.Monad
import Control.Applicative
import Data.List
import Propellor.Types
import Propellor.Engine
import Utility.Monad
import Utility.SafeCommand
import Utility.Env
@ -47,22 +43,3 @@ userScriptProperty :: UserName -> [String] -> Property
userScriptProperty user script = cmdProperty "su" ["-c", shellcmd, user]
where
shellcmd = intercalate " ; " ("set -e" : "cd" : script)
type ServiceName = String
-- | Ensures that a service is running.
--
-- 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
-- this means it's already running.
serviceRunning :: ServiceName -> Property
serviceRunning svc = Property ("running " ++ svc) $ do
void $ ensureProperty $
scriptProperty ["service " ++ shellEscape svc ++ " start >/dev/null 2>&1 || true"]
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

@ -18,8 +18,7 @@ job desc times user cddir command = ("/etc/cron.d/" ++ desc) `File.hasContent`
, ""
, times ++ "\t" ++ user ++ "\t" ++ "cd " ++ cddir ++ " && " ++ command
]
`requires` Apt.installed ["cron"]
`requires` serviceRunning "cron"
`requires` Apt.serviceInstalledRunning "cron"
`describe` ("cronned " ++ desc)
-- | Installs a cron job, and runs it niced and ioniced.

View File

@ -3,15 +3,15 @@ module Propellor.Property.OpenId where
import Propellor
import qualified Propellor.Property.File as File
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.Service as Service
import Data.List
providerFor :: [UserName] -> String -> Property
providerFor users baseurl = propertyList desc $
[ serviceRunning "apache2"
`requires` Apt.installed ["apache2"]
[ Apt.serviceInstalledRunning "apache2"
, Apt.installed ["simpleid"]
`onChange` serviceRestarted "apache2"
`onChange` Service.restarted "apache2"
, File.fileProperty desc
(map setbaseurl) "/etc/simpleid/config.inc"
] ++ map identfile users

View File

@ -0,0 +1,25 @@
module Propellor.Property.Service where
import Propellor
import Utility.SafeCommand
type ServiceName = String
-- | Ensures that a service is running. Does not ensure that
-- any package providing that service is installed. See
-- Apt.serviceInstalledRunning
--
-- 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
-- this means it's already running.
running :: ServiceName -> Property
running svc = Property ("running " ++ svc) $ do
void $ ensureProperty $
scriptProperty ["service " ++ shellEscape svc ++ " start >/dev/null 2>&1 || true"]
return NoChange
restarted :: ServiceName -> Property
restarted svc = Property ("restarted " ++ svc) $ do
void $ ensureProperty $
scriptProperty ["service " ++ shellEscape svc ++ " restart >/dev/null 2>&1 || true"]
return NoChange

View File

@ -24,7 +24,7 @@ builder arch crontimes rsyncupload = combineProperties "gitannexbuilder"
, Apt.buildDep ["git-annex"]
, Apt.installed ["git", "rsync", "moreutils", "ca-certificates",
"liblockfile-simple-perl", "cabal-install", "vim", "less"]
, serviceRunning "cron" `requires` Apt.installed ["cron"]
, Apt.serviceInstalledRunning "cron"
, User.accountFor builduser
, check (not <$> doesDirectoryExist gitbuilderdir) $ userScriptProperty builduser
[ "git clone git://git.kitenet.net/gitannexbuilder " ++ gitbuilderdir

View File

@ -68,8 +68,7 @@ container _parenthost name
[ Docker.publish "8080:80"
, Docker.volume "/var/www:/var/www"
, Docker.inside $ props
& serviceRunning "apache2"
`requires` Apt.installed ["apache2"]
& Apt.serviceInstalledRunning "apache2"
& Apt.unattendedUpgrades
]

View File

@ -47,7 +47,6 @@ container _ "webserver" = Just $ Docker.containerFrom "joeyh/debian-unstable"
[ Docker.publish "80:80"
, Docker.volume "/var/www:/var/www"
, Docker.inside $ props
& serviceRunning "apache2"
`requires` Apt.installed ["apache2"]
& Apt.serviceInstalledRunning "apache2"
]
container _ _ = Nothing