Commit 670e954a authored by Thomas Thrainer's avatar Thomas Thrainer
Browse files

Add queryd daemon (split from confd)



queryd is added as a new daemon which handles configuration queries over
LUXI. This functionality was removed from confd, which now only queries
over the network.

The queryd user is added to the master group such that it can access
server.pem. The confd user no longer needs to be in the master group.
This fixes issue 292.
Signed-off-by: default avatarThomas Thrainer <thomasth@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 218e3b0f
...@@ -124,7 +124,9 @@ ...@@ -124,7 +124,9 @@
/src/mon-collector /src/mon-collector
/src/htools /src/htools
/src/hconfd /src/hconfd
/src/hqueryd
/src/ganeti-confd /src/ganeti-confd
/src/ganeti-queryd
/src/ganeti-mond /src/ganeti-mond
/src/rpc-test /src/rpc-test
......
...@@ -201,6 +201,7 @@ CLEANFILES = \ ...@@ -201,6 +201,7 @@ CLEANFILES = \
$(HS_ALL_PROGS) $(HS_BUILT_SRCS) \ $(HS_ALL_PROGS) $(HS_BUILT_SRCS) \
$(HS_BUILT_TEST_HELPERS) \ $(HS_BUILT_TEST_HELPERS) \
src/ganeti-confd \ src/ganeti-confd \
src/ganeti-queryd \
src/ganeti-mond \ src/ganeti-mond \
.hpc/*.mix src/*.tix test/hs/*.tix \ .hpc/*.mix src/*.tix test/hs/*.tix \
doc/hs-lint.html doc/hs-lint.html
...@@ -214,7 +215,7 @@ HS_GENERATED_FILES = ...@@ -214,7 +215,7 @@ HS_GENERATED_FILES =
if WANT_HTOOLS if WANT_HTOOLS
HS_GENERATED_FILES += $(HS_PROGS) HS_GENERATED_FILES += $(HS_PROGS)
if ENABLE_CONFD if ENABLE_CONFD
HS_GENERATED_FILES += src/hconfd src/ganeti-confd HS_GENERATED_FILES += src/hconfd src/ganeti-confd src/hqueryd src/ganeti-queryd
endif endif
if ENABLE_MOND if ENABLE_MOND
...@@ -478,6 +479,7 @@ endif ...@@ -478,6 +479,7 @@ endif
HS_COMPILE_PROGS= \ HS_COMPILE_PROGS= \
src/ganeti-mond \ src/ganeti-mond \
src/hconfd \ src/hconfd \
src/hqueryd \
src/rpc-test src/rpc-test
# All Haskell non-test programs to be compiled but not automatically installed # All Haskell non-test programs to be compiled but not automatically installed
...@@ -868,7 +870,11 @@ if ENABLE_CONFD ...@@ -868,7 +870,11 @@ if ENABLE_CONFD
src/ganeti-confd: src/hconfd src/ganeti-confd: src/hconfd
cp -f $< $@ cp -f $< $@
src/ganeti-queryd: src/hqueryd
cp -f $< $@
nodist_sbin_SCRIPTS += src/ganeti-confd nodist_sbin_SCRIPTS += src/ganeti-confd
nodist_sbin_SCRIPTS += src/ganeti-queryd
endif endif
if ENABLE_MOND if ENABLE_MOND
...@@ -1532,6 +1538,8 @@ lib/_autoconf.py: Makefile | stamp-directories ...@@ -1532,6 +1538,8 @@ lib/_autoconf.py: Makefile | stamp-directories
echo "RAPI_GROUP = '$(RAPI_GROUP)'"; \ echo "RAPI_GROUP = '$(RAPI_GROUP)'"; \
echo "CONFD_USER = '$(CONFD_USER)'"; \ echo "CONFD_USER = '$(CONFD_USER)'"; \
echo "CONFD_GROUP = '$(CONFD_GROUP)'"; \ echo "CONFD_GROUP = '$(CONFD_GROUP)'"; \
echo "QUERYD_USER = '$(QUERYD_USER)'"; \
echo "QUERYD_GROUP = '$(QUERYD_GROUP)'"; \
echo "NODED_USER = '$(NODED_USER)'"; \ echo "NODED_USER = '$(NODED_USER)'"; \
echo "NODED_GROUP = '$(NODED_GROUP)'"; \ echo "NODED_GROUP = '$(NODED_GROUP)'"; \
echo "MOND_USER = '$(MOND_USER)'"; \ echo "MOND_USER = '$(MOND_USER)'"; \
...@@ -1613,11 +1621,13 @@ $(REPLACE_VARS_SED): $(SHELL_ENV_INIT) Makefile stamp-directories ...@@ -1613,11 +1621,13 @@ $(REPLACE_VARS_SED): $(SHELL_ENV_INIT) Makefile stamp-directories
echo 's#@''GNTMASTERUSER@#$(MASTERD_USER)#g'; \ echo 's#@''GNTMASTERUSER@#$(MASTERD_USER)#g'; \
echo 's#@''GNTRAPIUSER@#$(RAPI_USER)#g'; \ echo 's#@''GNTRAPIUSER@#$(RAPI_USER)#g'; \
echo 's#@''GNTCONFDUSER@#$(CONFD_USER)#g'; \ echo 's#@''GNTCONFDUSER@#$(CONFD_USER)#g'; \
echo 's#@''GNTQUERYDUSER@#$(QUERY_USER)#g'; \
echo 's#@''GNTNODEDUSER@#$(NODED_USER)#g'; \ echo 's#@''GNTNODEDUSER@#$(NODED_USER)#g'; \
echo 's#@''GNTMONDUSER@#$(MOND_USER)#g'; \ echo 's#@''GNTMONDUSER@#$(MOND_USER)#g'; \
echo 's#@''GNTRAPIGROUP@#$(RAPI_GROUP)#g'; \ echo 's#@''GNTRAPIGROUP@#$(RAPI_GROUP)#g'; \
echo 's#@''GNTADMINGROUP@#$(ADMIN_GROUP)#g'; \ echo 's#@''GNTADMINGROUP@#$(ADMIN_GROUP)#g'; \
echo 's#@''GNTCONFDGROUP@#$(CONFD_GROUP)#g'; \ echo 's#@''GNTCONFDGROUP@#$(CONFD_GROUP)#g'; \
echo 's#@''GNTQUERYDGROUP@#$(QUERYD_GROUP)#g'; \
echo 's#@''GNTMASTERDGROUP@#$(MASTERD_GROUP)#g'; \ echo 's#@''GNTMASTERDGROUP@#$(MASTERD_GROUP)#g'; \
echo 's#@''GNTMONDGROUP@#$(MOND_GROUP)#g'; \ echo 's#@''GNTMONDGROUP@#$(MOND_GROUP)#g'; \
echo 's#@''GNTDAEMONSGROUP@#$(DAEMONS_GROUP)#g'; \ echo 's#@''GNTDAEMONSGROUP@#$(DAEMONS_GROUP)#g'; \
......
...@@ -243,16 +243,19 @@ AC_ARG_WITH([user-prefix], ...@@ -243,16 +243,19 @@ AC_ARG_WITH([user-prefix],
[user_masterd="${withval}masterd"; [user_masterd="${withval}masterd";
user_rapi="${withval}rapi"; user_rapi="${withval}rapi";
user_confd="${withval}confd"; user_confd="${withval}confd";
user_queryd="${withval}queryd";
user_noded="$user_default"; user_noded="$user_default";
user_mond="${withval}mond"], user_mond="${withval}mond"],
[user_masterd="$user_default"; [user_masterd="$user_default";
user_rapi="$user_default"; user_rapi="$user_default";
user_confd="$user_default"; user_confd="$user_default";
user_queryd="$user_default";
user_noded="$user_default"; user_noded="$user_default";
user_mond="$user_default"]) user_mond="$user_default"])
AC_SUBST(MASTERD_USER, $user_masterd) AC_SUBST(MASTERD_USER, $user_masterd)
AC_SUBST(RAPI_USER, $user_rapi) AC_SUBST(RAPI_USER, $user_rapi)
AC_SUBST(CONFD_USER, $user_confd) AC_SUBST(CONFD_USER, $user_confd)
AC_SUBST(QUERYD_USER, $user_queryd)
AC_SUBST(NODED_USER, $user_noded) AC_SUBST(NODED_USER, $user_noded)
AC_SUBST(MOND_USER, $user_mond) AC_SUBST(MOND_USER, $user_mond)
...@@ -266,6 +269,7 @@ AC_ARG_WITH([group-prefix], ...@@ -266,6 +269,7 @@ AC_ARG_WITH([group-prefix],
[group_rapi="${withval}rapi"; [group_rapi="${withval}rapi";
group_admin="${withval}admin"; group_admin="${withval}admin";
group_confd="${withval}confd"; group_confd="${withval}confd";
group_queryd="${withval}queryd";
group_masterd="${withval}masterd"; group_masterd="${withval}masterd";
group_noded="$group_default"; group_noded="$group_default";
group_daemons="${withval}daemons"; group_daemons="${withval}daemons";
...@@ -273,6 +277,7 @@ AC_ARG_WITH([group-prefix], ...@@ -273,6 +277,7 @@ AC_ARG_WITH([group-prefix],
[group_rapi="$group_default"; [group_rapi="$group_default";
group_admin="$group_default"; group_admin="$group_default";
group_confd="$group_default"; group_confd="$group_default";
group_queryd="$group_default";
group_masterd="$group_default"; group_masterd="$group_default";
group_noded="$group_default"; group_noded="$group_default";
group_daemons="$group_default"; group_daemons="$group_default";
...@@ -280,6 +285,7 @@ AC_ARG_WITH([group-prefix], ...@@ -280,6 +285,7 @@ AC_ARG_WITH([group-prefix],
AC_SUBST(RAPI_GROUP, $group_rapi) AC_SUBST(RAPI_GROUP, $group_rapi)
AC_SUBST(ADMIN_GROUP, $group_admin) AC_SUBST(ADMIN_GROUP, $group_admin)
AC_SUBST(CONFD_GROUP, $group_confd) AC_SUBST(CONFD_GROUP, $group_confd)
AC_SUBST(QUERYD_GROUP, $group_queryd)
AC_SUBST(MASTERD_GROUP, $group_masterd) AC_SUBST(MASTERD_GROUP, $group_masterd)
AC_SUBST(NODED_GROUP, $group_noded) AC_SUBST(NODED_GROUP, $group_noded)
AC_SUBST(DAEMONS_GROUP, $group_daemons) AC_SUBST(DAEMONS_GROUP, $group_daemons)
...@@ -289,6 +295,7 @@ AC_SUBST(MOND_GROUP, $group_mond) ...@@ -289,6 +295,7 @@ AC_SUBST(MOND_GROUP, $group_mond)
AC_MSG_NOTICE([Running ganeti-masterd as $group_masterd:$group_masterd]) AC_MSG_NOTICE([Running ganeti-masterd as $group_masterd:$group_masterd])
AC_MSG_NOTICE([Running ganeti-rapi as $user_rapi:$group_rapi]) AC_MSG_NOTICE([Running ganeti-rapi as $user_rapi:$group_rapi])
AC_MSG_NOTICE([Running ganeti-confd as $user_confd:$group_confd]) AC_MSG_NOTICE([Running ganeti-confd as $user_confd:$group_confd])
AC_MSG_NOTICE([Running ganeti-queryd as $user_queryd:$group_queryd])
AC_MSG_NOTICE([Group for daemons is $group_daemons]) AC_MSG_NOTICE([Group for daemons is $group_daemons])
AC_MSG_NOTICE([Group for clients is $group_admin]) AC_MSG_NOTICE([Group for clients is $group_admin])
......
...@@ -39,6 +39,7 @@ _confd_enabled() { ...@@ -39,6 +39,7 @@ _confd_enabled() {
if _confd_enabled; then if _confd_enabled; then
DAEMONS+=( ganeti-confd ) DAEMONS+=( ganeti-confd )
DAEMONS+=( ganeti-queryd )
fi fi
_mond_enabled() { _mond_enabled() {
...@@ -52,6 +53,7 @@ fi ...@@ -52,6 +53,7 @@ fi
NODED_ARGS= NODED_ARGS=
MASTERD_ARGS= MASTERD_ARGS=
CONFD_ARGS= CONFD_ARGS=
QUERYD_ARGS=
RAPI_ARGS= RAPI_ARGS=
MOND_ARGS= MOND_ARGS=
...@@ -82,6 +84,9 @@ _daemon_usergroup() { ...@@ -82,6 +84,9 @@ _daemon_usergroup() {
confd) confd)
echo "@GNTCONFDUSER@:@GNTDAEMONSGROUP@" echo "@GNTCONFDUSER@:@GNTDAEMONSGROUP@"
;; ;;
queryd)
echo "@GNTQUERYDUSER@:@GNTQUERYDGROUP@"
;;
rapi) rapi)
echo "@GNTRAPIUSER@:@GNTRAPIGROUP@" echo "@GNTRAPIUSER@:@GNTRAPIGROUP@"
;; ;;
...@@ -228,7 +233,8 @@ start() { ...@@ -228,7 +233,8 @@ start() {
local usergroup=$(_daemon_usergroup $plain_name) local usergroup=$(_daemon_usergroup $plain_name)
local daemonexec=$(_daemon_executable $name) local daemonexec=$(_daemon_executable $name)
if [[ "$name" == ganeti-confd ]] && ! _confd_enabled; then if ( [[ "$name" == ganeti-confd ]] || [[ "$name" == ganeti-queryd ]] ) \
&& ! _confd_enabled; then
echo 'ganeti-confd disabled at build time' >&2 echo 'ganeti-confd disabled at build time' >&2
return 1 return 1
fi fi
......
...@@ -104,6 +104,8 @@ RAPI_USER = _autoconf.RAPI_USER ...@@ -104,6 +104,8 @@ RAPI_USER = _autoconf.RAPI_USER
RAPI_GROUP = _autoconf.RAPI_GROUP RAPI_GROUP = _autoconf.RAPI_GROUP
CONFD_USER = _autoconf.CONFD_USER CONFD_USER = _autoconf.CONFD_USER
CONFD_GROUP = _autoconf.CONFD_GROUP CONFD_GROUP = _autoconf.CONFD_GROUP
QUERYD_USER = _autoconf.QUERYD_USER
QUERYD_GROUP = _autoconf.QUERYD_GROUP
NODED_USER = _autoconf.NODED_USER NODED_USER = _autoconf.NODED_USER
NODED_GROUP = _autoconf.NODED_GROUP NODED_GROUP = _autoconf.NODED_GROUP
MOND_USER = _autoconf.MOND_USER MOND_USER = _autoconf.MOND_USER
...@@ -156,6 +158,7 @@ SCP = "scp" ...@@ -156,6 +158,7 @@ SCP = "scp"
NODED = "ganeti-noded" NODED = "ganeti-noded"
CONFD = "ganeti-confd" CONFD = "ganeti-confd"
QUERYD = "ganeti-queryd"
RAPI = "ganeti-rapi" RAPI = "ganeti-rapi"
MASTERD = "ganeti-masterd" MASTERD = "ganeti-masterd"
MOND = "ganeti-mond" MOND = "ganeti-mond"
...@@ -163,6 +166,7 @@ MOND = "ganeti-mond" ...@@ -163,6 +166,7 @@ MOND = "ganeti-mond"
DAEMONS = compat.UniqueFrozenset([ DAEMONS = compat.UniqueFrozenset([
NODED, NODED,
CONFD, CONFD,
QUERYD,
RAPI, RAPI,
MASTERD, MASTERD,
MOND, MOND,
...@@ -188,6 +192,7 @@ LAST_DRBD_PORT = 14999 ...@@ -188,6 +192,7 @@ LAST_DRBD_PORT = 14999
DAEMONS_LOGBASE = { DAEMONS_LOGBASE = {
NODED: "node-daemon", NODED: "node-daemon",
CONFD: "conf-daemon", CONFD: "conf-daemon",
QUERYD: "query-daemon",
RAPI: "rapi-daemon", RAPI: "rapi-daemon",
MASTERD: "master-daemon", MASTERD: "master-daemon",
MOND: "monitoring-daemon", MOND: "monitoring-daemon",
......
...@@ -75,6 +75,8 @@ class GetentResolver: ...@@ -75,6 +75,8 @@ class GetentResolver:
@ivar masterd_gid: The resolved gid of the masterd group @ivar masterd_gid: The resolved gid of the masterd group
@ivar confd_uid: The resolved uid of the confd user @ivar confd_uid: The resolved uid of the confd user
@ivar confd_gid: The resolved gid of the confd group @ivar confd_gid: The resolved gid of the confd group
@ivar queryd_uid: The resolved uid of the queryd user
@ivar queyrd_gid: The resolved gid of the queyrd group
@ivar rapi_uid: The resolved uid of the rapi user @ivar rapi_uid: The resolved uid of the rapi user
@ivar rapi_gid: The resolved gid of the rapi group @ivar rapi_gid: The resolved gid of the rapi group
@ivar noded_uid: The resolved uid of the noded user @ivar noded_uid: The resolved uid of the noded user
...@@ -93,6 +95,9 @@ class GetentResolver: ...@@ -93,6 +95,9 @@ class GetentResolver:
self.confd_uid = GetUid(constants.CONFD_USER, _getpwnam) self.confd_uid = GetUid(constants.CONFD_USER, _getpwnam)
self.confd_gid = GetGid(constants.CONFD_GROUP, _getgrnam) self.confd_gid = GetGid(constants.CONFD_GROUP, _getgrnam)
self.queryd_uid = GetUid(constants.QUERYD_USER, _getpwnam)
self.queryd_gid = GetGid(constants.QUERYD_GROUP, _getgrnam)
self.rapi_uid = GetUid(constants.RAPI_USER, _getpwnam) self.rapi_uid = GetUid(constants.RAPI_USER, _getpwnam)
self.rapi_gid = GetGid(constants.RAPI_GROUP, _getgrnam) self.rapi_gid = GetGid(constants.RAPI_GROUP, _getgrnam)
...@@ -106,6 +111,7 @@ class GetentResolver: ...@@ -106,6 +111,7 @@ class GetentResolver:
self._uid2user = { self._uid2user = {
self.masterd_uid: constants.MASTERD_USER, self.masterd_uid: constants.MASTERD_USER,
self.confd_uid: constants.CONFD_USER, self.confd_uid: constants.CONFD_USER,
self.queryd_uid: constants.QUERYD_USER,
self.rapi_uid: constants.RAPI_USER, self.rapi_uid: constants.RAPI_USER,
self.noded_uid: constants.NODED_USER, self.noded_uid: constants.NODED_USER,
} }
...@@ -113,6 +119,7 @@ class GetentResolver: ...@@ -113,6 +119,7 @@ class GetentResolver:
self._gid2group = { self._gid2group = {
self.masterd_gid: constants.MASTERD_GROUP, self.masterd_gid: constants.MASTERD_GROUP,
self.confd_gid: constants.CONFD_GROUP, self.confd_gid: constants.CONFD_GROUP,
self.queryd_gid: constants.QUERYD_GROUP,
self.rapi_gid: constants.RAPI_GROUP, self.rapi_gid: constants.RAPI_GROUP,
self.noded_gid: constants.NODED_GROUP, self.noded_gid: constants.NODED_GROUP,
self.daemons_gid: constants.DAEMONS_GROUP, self.daemons_gid: constants.DAEMONS_GROUP,
......
...@@ -180,7 +180,7 @@ def GetPaths(): ...@@ -180,7 +180,7 @@ def GetPaths():
(pathutils.MASTER_SOCKET, FILE, 0660, (pathutils.MASTER_SOCKET, FILE, 0660,
getent.masterd_uid, getent.daemons_gid, False), getent.masterd_uid, getent.daemons_gid, False),
(pathutils.QUERY_SOCKET, FILE, 0660, (pathutils.QUERY_SOCKET, FILE, 0660,
getent.confd_uid, getent.daemons_gid, False), getent.queryd_uid, getent.daemons_gid, False),
(pathutils.BDEV_CACHE_DIR, DIR, 0755, (pathutils.BDEV_CACHE_DIR, DIR, 0755,
getent.noded_uid, getent.masterd_gid), getent.noded_uid, getent.masterd_gid),
(pathutils.UIDPOOL_LOCKDIR, DIR, 0750, (pathutils.UIDPOOL_LOCKDIR, DIR, 0750,
......
...@@ -52,7 +52,6 @@ import Ganeti.ConfigReader ...@@ -52,7 +52,6 @@ import Ganeti.ConfigReader
import Ganeti.Hash import Ganeti.Hash
import Ganeti.Logging import Ganeti.Logging
import qualified Ganeti.Constants as C import qualified Ganeti.Constants as C
import Ganeti.Query.Server (prepQueryD, runQueryD)
import Ganeti.Utils import Ganeti.Utils
-- * Types and constants definitions -- * Types and constants definitions
...@@ -250,15 +249,8 @@ listener s hmac resp = do ...@@ -250,15 +249,8 @@ listener s hmac resp = do
else logDebug "Invalid magic code!" >> return () else logDebug "Invalid magic code!" >> return ()
return () return ()
-- | Extract the configuration from our IORef.
configReader :: CRef -> ConfigReader
configReader cref = do
cdata <- readIORef cref
return $ liftM fst cdata
-- | Type alias for prepMain results -- | Type alias for prepMain results
type PrepResult = (S.Socket, (FilePath, S.Socket), type PrepResult = (S.Socket, IORef (Result (ConfigData, LinkIpMap)))
IORef (Result (ConfigData, LinkIpMap)))
-- | Check function for confd. -- | Check function for confd.
checkMain :: CheckFn (S.Family, S.SockAddr) checkMain :: CheckFn (S.Family, S.SockAddr)
...@@ -275,20 +267,16 @@ prepMain :: PrepFn (S.Family, S.SockAddr) PrepResult ...@@ -275,20 +267,16 @@ prepMain :: PrepFn (S.Family, S.SockAddr) PrepResult
prepMain _ (af_family, bindaddr) = do prepMain _ (af_family, bindaddr) = do
s <- S.socket af_family S.Datagram S.defaultProtocol s <- S.socket af_family S.Datagram S.defaultProtocol
S.bindSocket s bindaddr S.bindSocket s bindaddr
-- prepare the queryd listener
query_data <- prepQueryD Nothing
cref <- newIORef (Bad "Configuration not yet loaded") cref <- newIORef (Bad "Configuration not yet loaded")
return (s, query_data, cref) return (s, cref)
-- | Main function. -- | Main function.
main :: MainFn (S.Family, S.SockAddr) PrepResult main :: MainFn (S.Family, S.SockAddr) PrepResult
main _ _ (s, query_data, cref) = do main _ _ (s, cref) = do
let cfg_transform :: Result ConfigData -> Result (ConfigData, LinkIpMap) let cfg_transform :: Result ConfigData -> Result (ConfigData, LinkIpMap)
cfg_transform = liftM (\cfg -> (cfg, buildLinkIpInstnameMap cfg)) cfg_transform = liftM (\cfg -> (cfg, buildLinkIpInstnameMap cfg))
initConfigReader cfg_transform cref initConfigReader cfg_transform cref
hmac <- getClusterHmac hmac <- getClusterHmac
-- launch the queryd listener -- enter the responder loop
_ <- forkIO $ runQueryD query_data (configReader cref)
-- and finally enter the responder loop
forever $ listener s hmac (responder cref) forever $ listener s hmac (responder cref)
...@@ -50,6 +50,7 @@ import Control.Monad ...@@ -50,6 +50,7 @@ import Control.Monad
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Data.Word import Data.Word
import GHC.IO.Handle (hDuplicateTo) import GHC.IO.Handle (hDuplicateTo)
import Network.BSD (getHostName)
import qualified Network.Socket as Socket import qualified Network.Socket as Socket
import System.Console.GetOpt import System.Console.GetOpt
import System.Exit import System.Exit
...@@ -291,6 +292,36 @@ parseAddress opts defport = do ...@@ -291,6 +292,36 @@ parseAddress opts defport = do
(resolveAddr port saddr) (resolveAddr port saddr)
(ioErrorToResult $ "Invalid address " ++ saddr) (ioErrorToResult $ "Invalid address " ++ saddr)
-- | Environment variable to override the assumed host name of the
-- current node.
vClusterHostNameEnvVar :: String
vClusterHostNameEnvVar = "GANETI_HOSTNAME"
-- | Returns if the current node is the master node.
isMaster :: IO Bool
isMaster = do
let ioErrorToNothing :: IOError -> IO (Maybe String)
ioErrorToNothing _ = return Nothing
vcluster_node <- Control.Exception.catch
(liftM Just (getEnv vClusterHostNameEnvVar))
ioErrorToNothing
curNode <- case vcluster_node of
Just node_name -> return node_name
Nothing -> getHostName
masterNode <- Ssconf.getMasterNode Nothing
case masterNode of
Ok n -> return (curNode == n)
Bad _ -> return False
-- | Ensures that the daemon runs on the right node (and exits
-- gracefully if it doesnt)
ensureNode :: GanetiDaemon -> IO ()
ensureNode daemon = do
is_master <- isMaster
when (daemonOnlyOnMaster daemon && not is_master) $ do
putStrLn "Not master, exiting."
exitWith (ExitFailure C.exitNotmaster)
-- | Run an I\/O action that might throw an I\/O error, under a -- | Run an I\/O action that might throw an I\/O error, under a
-- handler that will simply annotate and re-throw the exception. -- handler that will simply annotate and re-throw the exception.
describeError :: String -> Maybe Handle -> Maybe FilePath -> IO a -> IO a describeError :: String -> Maybe Handle -> Maybe FilePath -> IO a -> IO a
...@@ -337,8 +368,11 @@ genericMain :: GanetiDaemon -- ^ The daemon we're running ...@@ -337,8 +368,11 @@ genericMain :: GanetiDaemon -- ^ The daemon we're running
-> IO () -> IO ()
genericMain daemon options check_fn prep_fn exec_fn = do genericMain daemon options check_fn prep_fn exec_fn = do
let progname = daemonName daemon let progname = daemonName daemon
(opts, args) <- parseArgs progname options (opts, args) <- parseArgs progname options
ensureNode daemon
exitUnless (null args) "This program doesn't take any arguments" exitUnless (null args) "This program doesn't take any arguments"
unless (optNoUserChecks opts) $ do unless (optNoUserChecks opts) $ do
......
...@@ -26,15 +26,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ...@@ -26,15 +26,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-} -}
module Ganeti.Query.Server module Ganeti.Query.Server
( prepQueryD ( main
, runQueryD , checkMain
, prepMain
) where ) where
import Control.Applicative import Control.Applicative
import Control.Concurrent import Control.Concurrent
import Control.Exception import Control.Exception
import Control.Monad (forever)
import Data.Bits (bitSize) import Data.Bits (bitSize)
import Data.Maybe import Data.IORef
import qualified Network.Socket as S import qualified Network.Socket as S
import qualified Text.JSON as J import qualified Text.JSON as J
import Text.JSON (showJSON, JSValue(..)) import Text.JSON (showJSON, JSValue(..))
...@@ -226,27 +228,37 @@ clientLoop client creader = do ...@@ -226,27 +228,37 @@ clientLoop client creader = do
then clientLoop client creader then clientLoop client creader
else closeClient client else closeClient client
-- | Main loop: accepts clients, forks an I/O thread to handle that -- | Main listener loop: accepts clients, forks an I/O thread to handle
-- client, and then restarts. -- that client.
mainLoop :: ConfigReader -> S.Socket -> IO () listener :: ConfigReader -> S.Socket -> IO ()
mainLoop creader socket = do listener creader socket = do
client <- acceptClient socket client <- acceptClient socket
_ <- forkIO $ clientLoop client creader _ <- forkIO $ clientLoop client creader
mainLoop creader socket return ()
-- | Function that prepares the server socket. -- | Type alias for prepMain results
prepQueryD :: Maybe FilePath -> IO (FilePath, S.Socket) type PrepResult = (FilePath, S.Socket, IORef (Result ConfigData))
prepQueryD fpath = do
def_socket <- Path.defaultQuerySocket -- | Check function for queryd.
let socket_path = fromMaybe def_socket fpath checkMain :: CheckFn ()
checkMain _ = return $ Right ()
-- | Prepare function for queryd.
prepMain :: PrepFn () PrepResult
prepMain _ _ = do
socket_path <- Path.defaultQuerySocket
cleanupSocket socket_path cleanupSocket socket_path
s <- describeError "binding to the Luxi socket" s <- describeError "binding to the Luxi socket"
Nothing (Just socket_path) $ getServer socket_path Nothing (Just socket_path) $ getServer socket_path
return (socket_path, s) cref <- newIORef (Bad "Configuration not yet loaded")
return (socket_path, s, cref)
-- | Main function.
main :: MainFn () PrepResult
main _ _ (socket_path, server, cref) = do
initConfigReader id cref
let creader = readIORef cref
-- | Main function that runs the query endpoint.
runQueryD :: (FilePath, S.Socket) -> ConfigReader -> IO ()
runQueryD (socket_path, server) creader =
finally finally
(mainLoop creader server) (forever $ listener creader server)
(closeServer socket_path server) (closeServer socket_path server)
...@@ -29,6 +29,7 @@ module Ganeti.Runtime ...@@ -29,6 +29,7 @@ module Ganeti.Runtime
, GanetiGroup(..) , GanetiGroup(..)
, RuntimeEnts , RuntimeEnts
, daemonName , daemonName
, daemonOnlyOnMaster
, daemonUser , daemonUser
, daemonGroup , daemonGroup
, daemonLogFile , daemonLogFile
...@@ -56,6 +57,7 @@ data GanetiDaemon = GanetiMasterd ...@@ -56,6 +57,7 @@ data GanetiDaemon = GanetiMasterd
| GanetiNoded | GanetiNoded
| GanetiRapi | GanetiRapi
| GanetiConfd | GanetiConfd
| GanetiQueryd
| GanetiMond | GanetiMond
deriving (Show, Enum, Bounded, Eq, Ord) deriving (Show, Enum, Bounded, Eq, Ord)
...@@ -75,14 +77,25 @@ daemonName GanetiMasterd = C.masterd ...@@ -75,14 +77,25 @@ daemonName GanetiMasterd = C.masterd
daemonName GanetiNoded = C.noded daemonName GanetiNoded = C.noded
daemonName GanetiRapi = C.rapi daemonName GanetiRapi = C.rapi
daemonName GanetiConfd = C.confd daemonName GanetiConfd = C.confd
daemonName GanetiQueryd