"""
+import os
+import errno
import sys
import SocketServer
import time
def __init__(self, address, rqhandler):
"""IOServer constructor
- Args:
- address: the address to bind this IOServer to
- rqhandler: RequestHandler type object
+ @param address: the address to bind this IOServer to
+ @param rqhandler: RequestHandler type object
"""
SocketServer.UnixStreamServer.__init__(self, address, rqhandler)
return queue.ArchiveJob(job_id)
elif method == luxi.REQ_AUTOARCHIVE_JOBS:
- age = args
- return queue.AutoArchiveJobs(age)
+ (age, timeout) = args
+ return queue.AutoArchiveJobs(age, timeout)
elif method == luxi.REQ_WAIT_FOR_JOB_CHANGE:
(job_id, fields, prev_job_info, prev_log_serial, timeout) = args
def ParseOptions():
"""Parse the command line options.
- Returns:
- (options, args) as from OptionParser.parse_args()
+ @return: (options, args) as from OptionParser.parse_args()
"""
parser = OptionParser(description="Ganeti master daemon",
continue
break
if retries == 0:
- logging.critical("Cluster inconsistent, most of the nodes didn't answer"
- " after multiple retries. Aborting startup")
- return False
+ logging.critical("Cluster inconsistent, most of the nodes didn't answer"
+ " after multiple retries. Aborting startup")
+ return False
# here a real node is at the top of the list
all_votes = sum(item[1] for item in votes)
top_node, top_votes = votes[0]
result = False
if top_node != myself:
logging.critical("It seems we are not the master (top-voted node"
- " is %s)", top_node)
+ " is %s with %d out of %d votes)", top_node, top_votes,
+ all_votes)
elif top_votes < all_votes - top_votes:
logging.critical("It seems we are not the master (%d votes for,"
" %d votes against)", top_votes, all_votes - top_votes)
utils.debug = options.debug
utils.no_fork = True
- ssconf.CheckMaster(options.debug)
+ if options.fork:
+ utils.CloseFDs()
+
+ rpc.Init()
+ try:
+ ssconf.CheckMaster(options.debug)
- # we believe we are the master, let's ask the other nodes...
- if not CheckAgreement():
- return
+ # we believe we are the master, let's ask the other nodes...
+ if not CheckAgreement():
+ return
- master = IOServer(constants.MASTER_SOCKET, ClientRqHandler)
+ dirs = [(constants.RUN_GANETI_DIR, constants.RUN_DIRS_MODE),
+ (constants.SOCKET_DIR, constants.SOCKET_DIR_MODE),
+ ]
+ for dir, mode in dirs:
+ try:
+ os.mkdir(dir, mode)
+ except EnvironmentError, err:
+ if err.errno != errno.EEXIST:
+ raise errors.GenericError("Cannot create needed directory"
+ " '%s': %s" % (constants.SOCKET_DIR, err))
+ if not os.path.isdir(dir):
+ raise errors.GenericError("%s is not a directory" % dir)
+
+ # This is safe to do as the pid file guarantees against
+ # concurrent execution.
+ utils.RemoveFile(constants.MASTER_SOCKET)
+
+ master = IOServer(constants.MASTER_SOCKET, ClientRqHandler)
+ finally:
+ rpc.Shutdown()
# become a daemon
if options.fork:
- utils.Daemonize(logfile=constants.LOG_MASTERDAEMON,
- noclose_fds=[master.fileno()])
+ utils.Daemonize(logfile=constants.LOG_MASTERDAEMON)
utils.WritePidFile(constants.MASTERD_PID)
+ try:
+ utils.SetupLogging(constants.LOG_MASTERDAEMON, debug=options.debug,
+ stderr_logging=not options.fork)
- utils.SetupLogging(constants.LOG_MASTERDAEMON, debug=options.debug,
- stderr_logging=not options.fork)
-
- logging.info("ganeti master daemon startup")
+ logging.info("Ganeti master daemon startup")
- # activate ip
- master_node = ssconf.SimpleConfigReader().GetMasterNode()
- if not rpc.RpcRunner.call_node_start_master(master_node, False):
- logging.error("Can't activate master IP address")
+ rpc.Init()
+ try:
+ # activate ip
+ master_node = ssconf.SimpleConfigReader().GetMasterNode()
+ if not rpc.RpcRunner.call_node_start_master(master_node, False):
+ logging.error("Can't activate master IP address")
- master.setup_queue()
- try:
- master.serve_forever()
+ master.setup_queue()
+ try:
+ master.serve_forever()
+ finally:
+ master.server_cleanup()
+ finally:
+ rpc.Shutdown()
finally:
- master.server_cleanup()
utils.RemovePidFile(constants.MASTERD_PID)
+ utils.RemoveFile(constants.MASTER_SOCKET)
if __name__ == "__main__":