summaryrefslogtreecommitdiff
path: root/Propellor
diff options
context:
space:
mode:
authorJoey Hess2014-04-15 15:08:40 -0400
committerJoey Hess2014-04-15 15:08:40 -0400
commitba058d77a778058887f5c678b10e3c5ac599c50c (patch)
treef841754cb52d41ccafee719a1fc0b47c766ad7b2 /Propellor
parenta1e3c4e9e060c58a738501030a197557e20e88db (diff)
parent0592ab4bd7deaadaa971bc7d19b7beaca5a1253e (diff)
Merge branch 'joeyconfig'
Diffstat (limited to 'Propellor')
-rw-r--r--Propellor/Property.hs13
-rw-r--r--Propellor/Property/Apache.hs8
-rw-r--r--Propellor/Property/Apt.hs4
-rw-r--r--Propellor/Property/Hostname.hs7
-rw-r--r--Propellor/Property/Postfix.hs25
-rw-r--r--Propellor/Property/SiteSpecific/JoeySites.hs43
6 files changed, 90 insertions, 10 deletions
diff --git a/Propellor/Property.hs b/Propellor/Property.hs
index 95d17c05..5b1800ef 100644
--- a/Propellor/Property.hs
+++ b/Propellor/Property.hs
@@ -92,6 +92,19 @@ check c property = Property (propertyDesc property) $ ifM (liftIO c)
, return NoChange
)
+-- | Marks a Property as trivial. It can only return FailedChange or
+-- NoChange.
+--
+-- Useful when it's just as expensive to check if a change needs
+-- to be made as it is to just idempotently assure the property is
+-- satisfied. For example, chmodding a file.
+trivial :: Property -> Property
+trivial p = Property (propertyDesc p) $ do
+ r <- ensureProperty p
+ if r == MadeChange
+ then return NoChange
+ else return r
+
-- | Makes a property that is satisfied differently depending on the host's
-- operating system.
--
diff --git a/Propellor/Property/Apache.hs b/Propellor/Property/Apache.hs
index f45ef9df..cf3e62cc 100644
--- a/Propellor/Property/Apache.hs
+++ b/Propellor/Property/Apache.hs
@@ -10,12 +10,12 @@ type ConfigFile = [String]
siteEnabled :: HostName -> ConfigFile -> RevertableProperty
siteEnabled hn cf = RevertableProperty enable disable
where
- enable = cmdProperty "a2ensite" ["--quiet", hn]
+ enable = trivial $ cmdProperty "a2ensite" ["--quiet", hn]
`describe` ("apache site enabled " ++ hn)
`requires` siteAvailable hn cf
`requires` installed
`onChange` reloaded
- disable = File.notPresent (siteCfg hn)
+ disable = trivial $ File.notPresent (siteCfg hn)
`describe` ("apache site disabled " ++ hn)
`onChange` cmdProperty "a2dissite" ["--quiet", hn]
`requires` installed
@@ -30,11 +30,11 @@ siteAvailable hn cf = siteCfg hn `File.hasContent` (comment:cf)
modEnabled :: String -> RevertableProperty
modEnabled modname = RevertableProperty enable disable
where
- enable = cmdProperty "a2enmod" ["--quiet", modname]
+ enable = trivial $ cmdProperty "a2enmod" ["--quiet", modname]
`describe` ("apache module enabled " ++ modname)
`requires` installed
`onChange` reloaded
- disable = cmdProperty "a2dismod" ["--quiet", modname]
+ disable = trivial $ cmdProperty "a2dismod" ["--quiet", modname]
`describe` ("apache module disabled " ++ modname)
`requires` installed
`onChange` reloaded
diff --git a/Propellor/Property/Apt.hs b/Propellor/Property/Apt.hs
index f45bc2e6..3842cb02 100644
--- a/Propellor/Property/Apt.hs
+++ b/Propellor/Property/Apt.hs
@@ -103,7 +103,7 @@ installed' params ps = robustly $ check (isInstallable ps) go
go = runApt $ params ++ ["install"] ++ ps
installedBackport :: [Package] -> Property
-installedBackport ps = withOS desc $ \o -> case o of
+installedBackport ps = trivial $ withOS desc $ \o -> case o of
Nothing -> error "cannot install backports; os not declared"
(Just (System (Debian suite) _))
| isStable suite ->
@@ -200,7 +200,7 @@ reConfigure package vals = reconfigure `requires` setselections
forM_ vals $ \(tmpl, tmpltype, value) ->
hPutStrLn h $ unwords [package, tmpl, tmpltype, value]
hClose h
- reconfigure = cmdProperty "dpkg-reconfigure" ["-fnone", package]
+ reconfigure = cmdProperty' "dpkg-reconfigure" ["-fnone", package] noninteractiveEnv
-- | Ensures that a service is installed and running.
--
diff --git a/Propellor/Property/Hostname.hs b/Propellor/Property/Hostname.hs
index 03613ac9..30e0992d 100644
--- a/Propellor/Property/Hostname.hs
+++ b/Propellor/Property/Hostname.hs
@@ -4,11 +4,10 @@ import Propellor
import qualified Propellor.Property.File as File
-- | Ensures that the hostname is set to the HostAttr value.
--- Configures both /etc/hostname and the current hostname.
+-- Configures /etc/hostname and the current hostname.
--
--- When the hostname is a FQDN, also configures /etc/hosts,
--- with an entry for 127.0.1.1, which is standard at least on Debian
--- to set the FDQN (127.0.0.1 is localhost).
+-- A FQDN also configures /etc/hosts, with an entry for 127.0.1.1, which is
+-- standard at least on Debian to set the FDQN (127.0.0.1 is localhost).
sane :: Property
sane = Property ("sane hostname") (ensureProperty . setTo =<< getHostName)
diff --git a/Propellor/Property/Postfix.hs b/Propellor/Property/Postfix.hs
new file mode 100644
index 00000000..f4be27cf
--- /dev/null
+++ b/Propellor/Property/Postfix.hs
@@ -0,0 +1,25 @@
+module Propellor.Property.Postfix where
+
+import Propellor
+import qualified Propellor.Property.Apt as Apt
+
+installed :: Property
+installed = Apt.serviceInstalledRunning "postfix"
+
+-- | Configures postfix as a satellite system, which
+-- relats all mail through a relay host, which defaults to smtp.domain.
+--
+-- The smarthost may refuse to relay mail on to other domains, without
+-- futher coniguration/keys. But this should be enough to get cron job
+-- mail flowing to a place where it will be seen.
+satellite :: Property
+satellite = setup `requires` installed
+ where
+ setup = trivial $ Property "postfix satellite system" $ do
+ hn <- getHostName
+ ensureProperty $ Apt.reConfigure "postfix"
+ [ ("postfix/main_mailer_type", "select", "Satellite system")
+ , ("postfix/root_address", "string", "root")
+ , ("postfix/destinations", "string", " ")
+ , ("postfix/mailname", "string", hn)
+ ]
diff --git a/Propellor/Property/SiteSpecific/JoeySites.hs b/Propellor/Property/SiteSpecific/JoeySites.hs
index 73a8f71f..dd24bb6c 100644
--- a/Propellor/Property/SiteSpecific/JoeySites.hs
+++ b/Propellor/Property/SiteSpecific/JoeySites.hs
@@ -9,6 +9,7 @@ import qualified Propellor.Property.File as File
import qualified Propellor.Property.Gpg as Gpg
import qualified Propellor.Property.Ssh as Ssh
import qualified Propellor.Property.Git as Git
+import qualified Propellor.Property.Cron as Cron
import qualified Propellor.Property.Service as Service
import qualified Propellor.Property.User as User
import qualified Propellor.Property.Obnam as Obnam
@@ -127,6 +128,8 @@ annexWebSite hosts origin hn uuid remotes = propertyList (hn ++" website using g
, " <Directory /srv/web/"++hn++">"
, " Options Indexes FollowSymLinks ExecCGI"
, " AllowOverride None"
+ , " AddHandler cgi-script .cgi"
+ , " DirectoryIndex index.html index.cgi"
, " Order allow,deny"
, " allow from all"
, " </Directory>"
@@ -169,3 +172,43 @@ mainhttpscert True =
, " SSLCertificateKeyFile /etc/ssl/private/web.pem"
, " SSLCertificateChainFile /etc/ssl/certs/startssl.pem"
]
+
+
+annexRsyncServer :: Property
+annexRsyncServer = combineProperties "rsync server for git-annex autobuilders"
+ [ Apt.installed ["rsync"]
+ , File.hasPrivContent "/etc/rsyncd.conf"
+ , File.hasPrivContent "/etc/rsyncd.secrets"
+ , "/etc/default/rsync" `File.containsLine` "RSYNC_ENABLE=true"
+ `onChange` Service.running "rsync"
+ , endpoint "/srv/web/downloads.kitenet.net/git-annex/autobuild"
+ , endpoint "/srv/web/downloads.kitenet.net/git-annex/autobuild/x86_64-apple-mavericks"
+ ]
+ where
+ endpoint d = combineProperties ("endpoint " ++ d)
+ [ File.dirExists d
+ , File.ownerGroup d "joey" "joey"
+ ]
+
+-- Twitter, you kill us.
+twitRss :: Property
+twitRss = combineProperties "twitter rss"
+ [ Git.cloned "joey" "git://git.kitenet.net/twitrss.git" dir Nothing
+ , check (not <$> doesFileExist (dir </> "twitRss")) $
+ userScriptProperty "joey"
+ [ "cd " ++ dir
+ , "ghc --make twitRss"
+ ]
+ `requires` Apt.installed
+ [ "libghc-xml-dev"
+ , "libghc-feed-dev"
+ , "libghc-tagsoup-dev"
+ ]
+ , feed "http://twitter.com/search/realtime?q=git-annex" "git-annex-twitter"
+ , feed "http://twitter.com/search/realtime?q=olduse+OR+git-annex+OR+debhelper+OR+etckeeper+OR+ikiwiki+-ashley_ikiwiki" "twittergrep"
+ ]
+ where
+ dir = "/srv/web/tmp.kitenet.net/twitrss"
+ crontime = "15 * * * *"
+ feed url desc = Cron.job desc crontime "joey" dir $
+ "./twitRss " ++ shellEscape url ++ " > " ++ shellEscape ("../" ++ desc ++ ".rss")