2014-03-31 03:37:54 +00:00
|
|
|
module Propellor.Property.Hostname where
|
2014-03-30 03:45:48 +00:00
|
|
|
|
2014-03-31 03:55:59 +00:00
|
|
|
import Propellor
|
2014-03-31 03:37:54 +00:00
|
|
|
import qualified Propellor.Property.File as File
|
2014-03-30 03:45:48 +00:00
|
|
|
|
2014-07-06 16:23:57 +00:00
|
|
|
-- | Ensures that the hostname is set using best practices.
|
|
|
|
--
|
2014-04-14 19:17:31 +00:00
|
|
|
-- Configures /etc/hostname and the current hostname.
|
2014-04-04 03:57:36 +00:00
|
|
|
--
|
2014-07-06 16:23:57 +00:00
|
|
|
-- /etc/hosts is also configured, with an entry for 127.0.1.1, which is
|
|
|
|
-- standard at least on Debian to set the FDQN.
|
|
|
|
--
|
|
|
|
-- Also, the /etc/hosts 127.0.0.1 line is set to localhost. Putting any
|
|
|
|
-- other hostnames there is not best practices and can lead to annoying
|
|
|
|
-- messages from eg, apache.
|
2014-04-10 21:46:03 +00:00
|
|
|
sane :: Property
|
2014-06-01 00:48:23 +00:00
|
|
|
sane = property ("sane hostname") (ensureProperty . setTo =<< asks hostName)
|
2014-04-10 21:46:03 +00:00
|
|
|
|
|
|
|
setTo :: HostName -> Property
|
2014-04-11 01:09:20 +00:00
|
|
|
setTo hn = combineProperties desc go
|
2014-04-04 03:35:36 +00:00
|
|
|
where
|
2014-04-11 01:09:20 +00:00
|
|
|
desc = "hostname " ++ hn
|
|
|
|
(basehost, domain) = separate (== '.') hn
|
2014-04-04 03:57:36 +00:00
|
|
|
|
|
|
|
go = catMaybes
|
2014-04-11 01:09:20 +00:00
|
|
|
[ Just $ "/etc/hostname" `File.hasContent` [basehost]
|
2014-04-04 03:57:36 +00:00
|
|
|
, if null domain
|
|
|
|
then Nothing
|
2014-07-06 16:23:57 +00:00
|
|
|
else Just $ hostsline "127.0.1.1" [hn, basehost]
|
|
|
|
, Just $ hostsline "127.0.0.1" ["localhost"]
|
2014-05-19 21:29:46 +00:00
|
|
|
, Just $ trivial $ cmdProperty "hostname" [basehost]
|
2014-04-04 03:57:36 +00:00
|
|
|
]
|
|
|
|
|
2014-07-06 16:23:57 +00:00
|
|
|
hostsline ip names = File.fileProperty desc
|
|
|
|
(addhostsline ip names)
|
|
|
|
"/etc/hosts"
|
|
|
|
addhostsline ip names ls =
|
|
|
|
(ip ++ "\t" ++ (unwords names)) : filter (not . hasip ip) ls
|
|
|
|
hasip ip l = headMaybe (words l) == Just ip
|