Revision 04ccf5e9 daemons/ganeti-noded
b/daemons/ganeti-noded | ||
---|---|---|
732 | 732 |
return backend.ValidateHVParams(hvname, hvparams) |
733 | 733 |
|
734 | 734 |
|
735 |
def ParseOptions(): |
|
736 |
"""Parse the command line options. |
|
737 |
|
|
738 |
@return: (options, args) as from OptionParser.parse_args() |
|
735 |
def CheckNODED(options, args): |
|
736 |
"""Initial checks whether to run exit with a failure |
|
739 | 737 |
|
740 | 738 |
""" |
741 |
parser = OptionParser(description="Ganeti node daemon", |
|
742 |
usage="%prog [-f] [-d] [-b ADDRESS]", |
|
743 |
version="%%prog (ganeti) %s" % |
|
744 |
constants.RELEASE_VERSION) |
|
745 |
|
|
746 |
parser.add_option("-f", "--foreground", dest="fork", |
|
747 |
help="Don't detach from the current terminal", |
|
748 |
default=True, action="store_false") |
|
749 |
parser.add_option("-d", "--debug", dest="debug", |
|
750 |
help="Enable some debug messages", |
|
751 |
default=False, action="store_true") |
|
752 |
parser.add_option("-b", "--bind", dest="bind_address", |
|
753 |
help="Bind address", |
|
754 |
default="", metavar="ADDRESS") |
|
755 |
|
|
756 |
options, args = parser.parse_args() |
|
757 |
return options, args |
|
739 |
for fname in (constants.SSL_CERT_FILE,): |
|
740 |
if not os.path.isfile(fname): |
|
741 |
print "config %s not there, will not run." % fname |
|
742 |
sys.exit(constants.EXIT_NOTCLUSTER) |
|
758 | 743 |
|
759 | 744 |
|
760 |
def main():
|
|
761 |
"""Main function for the node daemon.
|
|
745 |
def ExecNODED(options, args):
|
|
746 |
"""Main NODED function, executed with the pidfile held.
|
|
762 | 747 |
|
763 | 748 |
""" |
764 | 749 |
global queue_lock |
765 |
daemon_name = constants.NODED |
|
766 | 750 |
|
767 |
options, args = ParseOptions() |
|
751 |
# Read SSL certificate |
|
752 |
ssl_params = http.HttpSslParams(ssl_key_path=constants.SSL_CERT_FILE, |
|
753 |
ssl_cert_path=constants.SSL_CERT_FILE) |
|
768 | 754 |
|
769 |
if options.fork:
|
|
770 |
utils.CloseFDs()
|
|
755 |
# Prepare job queue
|
|
756 |
queue_lock = jstore.InitAndVerifyQueue(must_lock=False)
|
|
771 | 757 |
|
772 |
for fname in (constants.SSL_CERT_FILE,): |
|
773 |
if not os.path.isfile(fname): |
|
774 |
print "config %s not there, will not run." % fname |
|
775 |
sys.exit(constants.EXIT_NOTCLUSTER) |
|
758 |
mainloop = daemon.Mainloop() |
|
759 |
server = NodeHttpServer(mainloop, options.bind_address, options.port, |
|
760 |
ssl_params=ssl_params, ssl_verify_peer=True) |
|
761 |
server.Start() |
|
762 |
try: |
|
763 |
mainloop.Run() |
|
764 |
finally: |
|
765 |
server.Stop() |
|
776 | 766 |
|
777 |
port = utils.GetDaemonPort(constants.NODED) |
|
778 | 767 |
|
768 |
def main(): |
|
769 |
"""Main function for the node daemon. |
|
770 |
|
|
771 |
""" |
|
772 |
parser = OptionParser(description="Ganeti node daemon", |
|
773 |
usage="%prog [-f] [-d] [-p port] [-b ADDRESS]", |
|
774 |
version="%%prog (ganeti) %s" % |
|
775 |
constants.RELEASE_VERSION) |
|
779 | 776 |
dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS] |
780 | 777 |
dirs.append((constants.LOG_OS_DIR, 0750)) |
781 | 778 |
dirs.append((constants.LOCK_DIR, 1777)) |
782 |
utils.EnsureDirs(dirs) |
|
783 |
|
|
784 |
# become a daemon |
|
785 |
if options.fork: |
|
786 |
utils.Daemonize(logfile=constants.DAEMONS_LOGFILES[daemon_name]) |
|
787 |
|
|
788 |
utils.WritePidFile(daemon_name) |
|
789 |
try: |
|
790 |
utils.SetupLogging(logfile=constants.DAEMONS_LOGFILES[daemon_name], |
|
791 |
debug=options.debug, |
|
792 |
stderr_logging=not options.fork) |
|
793 |
logging.info("ganeti node daemon startup") |
|
794 |
|
|
795 |
# Read SSL certificate |
|
796 |
ssl_params = http.HttpSslParams(ssl_key_path=constants.SSL_CERT_FILE, |
|
797 |
ssl_cert_path=constants.SSL_CERT_FILE) |
|
798 |
|
|
799 |
# Prepare job queue |
|
800 |
queue_lock = jstore.InitAndVerifyQueue(must_lock=False) |
|
801 |
|
|
802 |
mainloop = daemon.Mainloop() |
|
803 |
server = NodeHttpServer(mainloop, options.bind_address, port, |
|
804 |
ssl_params=ssl_params, ssl_verify_peer=True) |
|
805 |
server.Start() |
|
806 |
try: |
|
807 |
mainloop.Run() |
|
808 |
finally: |
|
809 |
server.Stop() |
|
810 |
finally: |
|
811 |
utils.RemovePidFile(daemon_name) |
|
779 |
daemon.GenericMain(constants.NODED, parser, dirs, CheckNODED, ExecNODED) |
|
812 | 780 |
|
813 | 781 |
|
814 | 782 |
if __name__ == '__main__': |
Also available in: Unified diff