From 4c3f55b8c8baaa3af943e39c2d21093b133baa4f Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Thu, 1 Nov 2012 15:38:53 +0100 Subject: [PATCH] Split queryd run into prepare and exec This will help with the general daemon split of prepare/run, and flag errors earlier in the startup. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- htools/Ganeti/Confd/Server.hs | 6 ++++-- htools/Ganeti/Query/Server.hs | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/htools/Ganeti/Confd/Server.hs b/htools/Ganeti/Confd/Server.hs index 35aab41b8..39bef213b 100644 --- a/htools/Ganeti/Confd/Server.hs +++ b/htools/Ganeti/Confd/Server.hs @@ -58,7 +58,7 @@ import Ganeti.Logging import Ganeti.Utils import qualified Ganeti.Constants as C import qualified Ganeti.Path as Path -import Ganeti.Query.Server (runQueryD) +import Ganeti.Query.Server (prepQueryD, runQueryD) -- * Types and constants definitions @@ -526,7 +526,9 @@ main opts _ _ = do _ <- forkIO $ onTimeoutTimer inotiaction Path.clusterConfFile cref statemvar -- fork the polling timer _ <- forkIO $ onReloadTimer inotiaction Path.clusterConfFile cref statemvar + -- prepare the queryd listener + query_data <- prepQueryD Nothing -- launch the queryd listener - _ <- forkIO $ runQueryD Nothing (configReader cref) + _ <- forkIO $ runQueryD query_data (configReader cref) -- and finally enter the responder loop forever $ listener s hmac (responder cref) diff --git a/htools/Ganeti/Query/Server.hs b/htools/Ganeti/Query/Server.hs index 6b33a9ea9..6909cc9c2 100644 --- a/htools/Ganeti/Query/Server.hs +++ b/htools/Ganeti/Query/Server.hs @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA module Ganeti.Query.Server ( ConfigReader + , prepQueryD , runQueryD ) where @@ -218,13 +219,17 @@ mainLoop creader socket = do _ <- forkIO $ clientLoop client creader mainLoop creader socket --- | Main function that runs the query endpoint. This should be the --- only one exposed from this module. -runQueryD :: Maybe FilePath -> ConfigReader -> IO () -runQueryD fpath creader = do +-- | Function that prepares the server socket. +prepQueryD :: Maybe FilePath -> IO (FilePath, S.Socket) +prepQueryD fpath = do let socket_path = fromMaybe Path.defaultQuerySocket fpath cleanupSocket socket_path - bracket - (getServer socket_path) - (closeServer socket_path) - (mainLoop creader) + s <- getServer socket_path + return (socket_path, s) + +-- | Main function that runs the query endpoint. +runQueryD :: (FilePath, S.Socket) -> ConfigReader -> IO () +runQueryD (socket_path, server) creader = + finally + (mainLoop creader server) + (closeServer socket_path server) -- GitLab