Commit ed0efaa5 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

ganeti-masterd: Master voting in separate process

One shouldn't fork a Python process after using threads. Master
voting is done before forking (utils.Daemonize), but it also uses
threads. Hence it's now called from a separate process.

This patch also fixes the check function to actually exit if
the current machine is not the master (introduced in 04ccf5e9

).
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 8a20c732
......@@ -442,27 +442,10 @@ def CheckAgreement():
return result
def CheckMasterd(options, args):
"""Initial checks whether to run or exit with a failure.
"""
def CheckAgreementWithRpc():
rpc.Init()
try:
ssconf.CheckMaster(options.debug)
# we believe we are the master, let's ask the other nodes...
if options.no_voting and not options.yes_do_it:
sys.stdout.write("The 'no voting' option has been selected.\n")
sys.stdout.write("This is dangerous, please confirm by"
" typing uppercase 'yes': ")
sys.stdout.flush()
confirmation = sys.stdin.readline().strip()
if confirmation != "YES":
print "Aborting."
return
elif not options.no_voting:
if not CheckAgreement():
return
return CheckAgreement()
finally:
rpc.Shutdown()
......@@ -511,6 +494,36 @@ def _RunInSeparateProcess(fn):
return bool(exitcode)
def CheckMasterd(options, args):
"""Initial checks whether to run or exit with a failure.
"""
ssconf.CheckMaster(options.debug)
# If CheckMaster didn't fail we believe we are the master, but we have to
# confirm with the other nodes.
if options.no_voting:
if options.yes_do_it:
return
sys.stdout.write("The 'no voting' option has been selected.\n")
sys.stdout.write("This is dangerous, please confirm by"
" typing uppercase 'yes': ")
sys.stdout.flush()
confirmation = sys.stdin.readline().strip()
if confirmation != "YES":
print >>sys.stderr, "Aborting."
sys.exit(constants.EXIT_FAILURE)
return
# CheckAgreement uses RPC and threads, hence it needs to be run in a separate
# process before we call utils.Daemonize in the current process.
if not _RunInSeparateProcess(CheckAgreementWithRpc):
sys.exit(constants.EXIT_FAILURE)
def ExecMasterd (options, args):
"""Main master daemon function, executed with the PID file held.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment