Revision 670e954a src/Ganeti/Confd/Server.hs
b/src/Ganeti/Confd/Server.hs | ||
---|---|---|
52 | 52 |
import Ganeti.Hash |
53 | 53 |
import Ganeti.Logging |
54 | 54 |
import qualified Ganeti.Constants as C |
55 |
import Ganeti.Query.Server (prepQueryD, runQueryD) |
|
56 | 55 |
import Ganeti.Utils |
57 | 56 |
|
58 | 57 |
-- * Types and constants definitions |
... | ... | |
250 | 249 |
else logDebug "Invalid magic code!" >> return () |
251 | 250 |
return () |
252 | 251 |
|
253 |
-- | Extract the configuration from our IORef. |
|
254 |
configReader :: CRef -> ConfigReader |
|
255 |
configReader cref = do |
|
256 |
cdata <- readIORef cref |
|
257 |
return $ liftM fst cdata |
|
258 |
|
|
259 | 252 |
-- | Type alias for prepMain results |
260 |
type PrepResult = (S.Socket, (FilePath, S.Socket), |
|
261 |
IORef (Result (ConfigData, LinkIpMap))) |
|
253 |
type PrepResult = (S.Socket, IORef (Result (ConfigData, LinkIpMap))) |
|
262 | 254 |
|
263 | 255 |
-- | Check function for confd. |
264 | 256 |
checkMain :: CheckFn (S.Family, S.SockAddr) |
... | ... | |
275 | 267 |
prepMain _ (af_family, bindaddr) = do |
276 | 268 |
s <- S.socket af_family S.Datagram S.defaultProtocol |
277 | 269 |
S.bindSocket s bindaddr |
278 |
-- prepare the queryd listener |
|
279 |
query_data <- prepQueryD Nothing |
|
280 | 270 |
cref <- newIORef (Bad "Configuration not yet loaded") |
281 |
return (s, query_data, cref)
|
|
271 |
return (s, cref) |
|
282 | 272 |
|
283 | 273 |
-- | Main function. |
284 | 274 |
main :: MainFn (S.Family, S.SockAddr) PrepResult |
285 |
main _ _ (s, query_data, cref) = do
|
|
275 |
main _ _ (s, cref) = do |
|
286 | 276 |
let cfg_transform :: Result ConfigData -> Result (ConfigData, LinkIpMap) |
287 | 277 |
cfg_transform = liftM (\cfg -> (cfg, buildLinkIpInstnameMap cfg)) |
288 | 278 |
initConfigReader cfg_transform cref |
289 | 279 |
|
290 | 280 |
hmac <- getClusterHmac |
291 |
-- launch the queryd listener |
|
292 |
_ <- forkIO $ runQueryD query_data (configReader cref) |
|
293 |
-- and finally enter the responder loop |
|
281 |
-- enter the responder loop |
|
294 | 282 |
forever $ listener s hmac (responder cref) |
Also available in: Unified diff