serviceInstalledRunning
This commit is contained in:
parent
7561ee0443
commit
a52a2a89df
|
@ -8,6 +8,7 @@ import Control.Monad
|
||||||
|
|
||||||
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.File (Line)
|
import Propellor.Property.File (Line)
|
||||||
|
|
||||||
sourcesList :: FilePath
|
sourcesList :: FilePath
|
||||||
|
@ -149,9 +150,7 @@ autoRemove = runApt ["-y", "autoremove"]
|
||||||
unattendedUpgrades :: RevertableProperty
|
unattendedUpgrades :: RevertableProperty
|
||||||
unattendedUpgrades = RevertableProperty enable disable
|
unattendedUpgrades = RevertableProperty enable disable
|
||||||
where
|
where
|
||||||
enable = setup True
|
enable = setup True `before` Service.running "cron"
|
||||||
`before` installed ["cron"]
|
|
||||||
`before` serviceRunning "cron"
|
|
||||||
disable = setup False
|
disable = setup False
|
||||||
|
|
||||||
setup enabled = (if enabled then installed else removed) ["unattended-upgrades"]
|
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]
|
hPutStrLn h $ unwords [package, template, tmpltype, value]
|
||||||
hClose h
|
hClose h
|
||||||
reconfigure = cmdProperty "dpkg-reconfigure" ["-fnone", package]
|
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]
|
||||||
|
|
|
@ -3,16 +3,12 @@ module Propellor.Property.Cmd (
|
||||||
cmdProperty',
|
cmdProperty',
|
||||||
scriptProperty,
|
scriptProperty,
|
||||||
userScriptProperty,
|
userScriptProperty,
|
||||||
serviceRunning,
|
|
||||||
serviceRestarted,
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
import Propellor.Types
|
import Propellor.Types
|
||||||
import Propellor.Engine
|
|
||||||
import Utility.Monad
|
import Utility.Monad
|
||||||
import Utility.SafeCommand
|
import Utility.SafeCommand
|
||||||
import Utility.Env
|
import Utility.Env
|
||||||
|
@ -47,22 +43,3 @@ userScriptProperty :: UserName -> [String] -> Property
|
||||||
userScriptProperty user script = cmdProperty "su" ["-c", shellcmd, user]
|
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.
|
|
||||||
--
|
|
||||||
-- 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
|
|
||||||
|
|
|
@ -18,8 +18,7 @@ job desc times user cddir command = ("/etc/cron.d/" ++ desc) `File.hasContent`
|
||||||
, ""
|
, ""
|
||||||
, times ++ "\t" ++ user ++ "\t" ++ "cd " ++ cddir ++ " && " ++ command
|
, times ++ "\t" ++ user ++ "\t" ++ "cd " ++ cddir ++ " && " ++ command
|
||||||
]
|
]
|
||||||
`requires` Apt.installed ["cron"]
|
`requires` Apt.serviceInstalledRunning "cron"
|
||||||
`requires` serviceRunning "cron"
|
|
||||||
`describe` ("cronned " ++ desc)
|
`describe` ("cronned " ++ desc)
|
||||||
|
|
||||||
-- | Installs a cron job, and runs it niced and ioniced.
|
-- | Installs a cron job, and runs it niced and ioniced.
|
||||||
|
|
|
@ -3,15 +3,15 @@ module Propellor.Property.OpenId 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
|
||||||
|
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
providerFor :: [UserName] -> String -> Property
|
providerFor :: [UserName] -> String -> Property
|
||||||
providerFor users baseurl = propertyList desc $
|
providerFor users baseurl = propertyList desc $
|
||||||
[ serviceRunning "apache2"
|
[ Apt.serviceInstalledRunning "apache2"
|
||||||
`requires` Apt.installed ["apache2"]
|
|
||||||
, Apt.installed ["simpleid"]
|
, Apt.installed ["simpleid"]
|
||||||
`onChange` serviceRestarted "apache2"
|
`onChange` Service.restarted "apache2"
|
||||||
, File.fileProperty desc
|
, File.fileProperty desc
|
||||||
(map setbaseurl) "/etc/simpleid/config.inc"
|
(map setbaseurl) "/etc/simpleid/config.inc"
|
||||||
] ++ map identfile users
|
] ++ map identfile users
|
||||||
|
|
|
@ -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
|
|
@ -24,7 +24,7 @@ builder arch crontimes rsyncupload = combineProperties "gitannexbuilder"
|
||||||
, Apt.buildDep ["git-annex"]
|
, Apt.buildDep ["git-annex"]
|
||||||
, Apt.installed ["git", "rsync", "moreutils", "ca-certificates",
|
, Apt.installed ["git", "rsync", "moreutils", "ca-certificates",
|
||||||
"liblockfile-simple-perl", "cabal-install", "vim", "less"]
|
"liblockfile-simple-perl", "cabal-install", "vim", "less"]
|
||||||
, serviceRunning "cron" `requires` Apt.installed ["cron"]
|
, Apt.serviceInstalledRunning "cron"
|
||||||
, User.accountFor builduser
|
, User.accountFor builduser
|
||||||
, check (not <$> doesDirectoryExist gitbuilderdir) $ userScriptProperty builduser
|
, check (not <$> doesDirectoryExist gitbuilderdir) $ userScriptProperty builduser
|
||||||
[ "git clone git://git.kitenet.net/gitannexbuilder " ++ gitbuilderdir
|
[ "git clone git://git.kitenet.net/gitannexbuilder " ++ gitbuilderdir
|
||||||
|
|
|
@ -68,8 +68,7 @@ container _parenthost name
|
||||||
[ Docker.publish "8080:80"
|
[ Docker.publish "8080:80"
|
||||||
, Docker.volume "/var/www:/var/www"
|
, Docker.volume "/var/www:/var/www"
|
||||||
, Docker.inside $ props
|
, Docker.inside $ props
|
||||||
& serviceRunning "apache2"
|
& Apt.serviceInstalledRunning "apache2"
|
||||||
`requires` Apt.installed ["apache2"]
|
|
||||||
& Apt.unattendedUpgrades
|
& Apt.unattendedUpgrades
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ container _ "webserver" = Just $ Docker.containerFrom "joeyh/debian-unstable"
|
||||||
[ Docker.publish "80:80"
|
[ Docker.publish "80:80"
|
||||||
, Docker.volume "/var/www:/var/www"
|
, Docker.volume "/var/www:/var/www"
|
||||||
, Docker.inside $ props
|
, Docker.inside $ props
|
||||||
& serviceRunning "apache2"
|
& Apt.serviceInstalledRunning "apache2"
|
||||||
`requires` Apt.installed ["apache2"]
|
|
||||||
]
|
]
|
||||||
container _ _ = Nothing
|
container _ _ = Nothing
|
||||||
|
|
Loading…
Reference in New Issue