diff options
| author | Joey Hess <joey@kitenet.net> | 2014-04-08 19:31:03 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-04-08 19:31:03 -0400 |
| commit | a52a2a89dfe92d7bed4a6446101657a288fd3bae (patch) | |
| tree | 207f98df36a858276269dcf87926566ea082018b /Propellor | |
| parent | 7561ee0443a33ffc0574dc6b606c9128da3fba4f (diff) | |
serviceInstalledRunning
Diffstat (limited to 'Propellor')
| -rw-r--r-- | Propellor/Property/Apt.hs | 12 | ||||
| -rw-r--r-- | Propellor/Property/Cmd.hs | 23 | ||||
| -rw-r--r-- | Propellor/Property/Cron.hs | 3 | ||||
| -rw-r--r-- | Propellor/Property/OpenId.hs | 6 | ||||
| -rw-r--r-- | Propellor/Property/Service.hs | 25 | ||||
| -rw-r--r-- | Propellor/Property/SiteSpecific/GitAnnexBuilder.hs | 2 |
6 files changed, 39 insertions, 32 deletions
diff --git a/Propellor/Property/Apt.hs b/Propellor/Property/Apt.hs index ac1d9a12..ff9b3de9 100644 --- a/Propellor/Property/Apt.hs +++ b/Propellor/Property/Apt.hs @@ -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] diff --git a/Propellor/Property/Cmd.hs b/Propellor/Property/Cmd.hs index f661cf81..c715fd2a 100644 --- a/Propellor/Property/Cmd.hs +++ b/Propellor/Property/Cmd.hs @@ -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 diff --git a/Propellor/Property/Cron.hs b/Propellor/Property/Cron.hs index 30bdb510..fa6019ea 100644 --- a/Propellor/Property/Cron.hs +++ b/Propellor/Property/Cron.hs @@ -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. diff --git a/Propellor/Property/OpenId.hs b/Propellor/Property/OpenId.hs index 4f22bdb9..c397bdb8 100644 --- a/Propellor/Property/OpenId.hs +++ b/Propellor/Property/OpenId.hs @@ -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 diff --git a/Propellor/Property/Service.hs b/Propellor/Property/Service.hs new file mode 100644 index 00000000..2fb3e0c6 --- /dev/null +++ b/Propellor/Property/Service.hs @@ -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 diff --git a/Propellor/Property/SiteSpecific/GitAnnexBuilder.hs b/Propellor/Property/SiteSpecific/GitAnnexBuilder.hs index 149c8e6c..580a52dc 100644 --- a/Propellor/Property/SiteSpecific/GitAnnexBuilder.hs +++ b/Propellor/Property/SiteSpecific/GitAnnexBuilder.hs @@ -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 |
