diff --git a/daemons/ganeti-masterd b/daemons/ganeti-masterd index 9b866b083d5ace24724f5937095fcfd086cc522a..cbccdce514732f27dd0a0950e6492ed97da557b1 100755 --- a/daemons/ganeti-masterd +++ b/daemons/ganeti-masterd @@ -265,32 +265,6 @@ class GanetiContext(object): object.__setattr__(self, name, value) -def CheckMaster(debug): - """Checks the node setup. - - If this is the master, the function will return. Otherwise it will - exit with an exit code based on the node status. - - """ - try: - ss = ssconf.SimpleStore() - master_name = ss.GetMasterNode() - except errors.ConfigurationError, err: - print "Cluster configuration incomplete: '%s'" % str(err) - sys.exit(EXIT_NODESETUP_ERROR) - - try: - myself = utils.HostInfo() - except errors.ResolverError, err: - sys.stderr.write("Cannot resolve my own name (%s)\n" % err.args[0]) - sys.exit(EXIT_NODESETUP_ERROR) - - if myself.name != master_name: - if debug: - sys.stderr.write("Not master, exiting.\n") - sys.exit(EXIT_NOTMASTER) - - def ParseOptions(): """Parse the command line options. @@ -320,7 +294,7 @@ def main(): utils.debug = options.debug utils.no_fork = True - CheckMaster(options.debug) + ssconf.CheckMaster(options.debug) master = IOServer(constants.MASTER_SOCKET, ClientRqHandler, GanetiContext()) diff --git a/daemons/ganeti-rapi b/daemons/ganeti-rapi index 1d0795c9014f52d6ed9deb95ee4ff4ec109dbb5d..c8e8953d39714be721320f5a9d4c1ca68557bc17 100755 --- a/daemons/ganeti-rapi +++ b/daemons/ganeti-rapi @@ -31,6 +31,7 @@ from ganeti import constants from ganeti import errors from ganeti import http from ganeti import rpc +from ganeti import ssconf from ganeti import utils from ganeti.rapi import connector @@ -129,6 +130,8 @@ def main(): """ options, args = ParseOptions() + ssconf.CheckMaster(options.debug) + if options.fork: utils.Daemonize(logfile=constants.LOG_RAPISERVER) diff --git a/lib/ssconf.py b/lib/ssconf.py index d73a267ac2b68a8c7f9a8398d8410d4667ef77e7..a18a5564894777cd3cc1dcfde319a1c11b3d2d20 100644 --- a/lib/ssconf.py +++ b/lib/ssconf.py @@ -27,6 +27,7 @@ configuration data, which is mostly static and available to all nodes. """ import socket +import sys from ganeti import errors from ganeti import constants @@ -199,3 +200,28 @@ class WritableSimpleStore(SimpleStore): utils.WriteFile(file_name, data="%s\n" % str(value), uid=0, gid=0, mode=0400) + +def CheckMaster(debug): + """Checks the node setup. + + If this is the master, the function will return. Otherwise it will + exit with an exit code based on the node status. + + """ + try: + ss = SimpleStore() + master_name = ss.GetMasterNode() + except errors.ConfigurationError, err: + print "Cluster configuration incomplete: '%s'" % str(err) + sys.exit(constants.EXIT_NODESETUP_ERROR) + + try: + myself = utils.HostInfo() + except errors.ResolverError, err: + sys.stderr.write("Cannot resolve my own name (%s)\n" % err.args[0]) + sys.exit(constants.EXIT_NODESETUP_ERROR) + + if myself.name != master_name: + if debug: + sys.stderr.write("Not master, exiting.\n") + sys.exit(constants.EXIT_NOTMASTER)