Commit 5338ee10 authored by Marco Mariani's avatar Marco Mariani

minor cleanup

parent d7ba4285
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: set et sts=2:
############################################################################## ##############################################################################
# #
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors. # Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
...@@ -56,7 +57,7 @@ def launchSupervisord(socket, configuration_file): ...@@ -56,7 +57,7 @@ def launchSupervisord(socket, configuration_file):
while trynum < 6: while trynum < 6:
try: try:
status = supervisor.getState() status = supervisor.getState()
except xmlrpclib.Fault, e: except xmlrpclib.Fault as e:
if e.faultCode == 6 and e.faultString == 'SHUTDOWN_STATE': if e.faultCode == 6 and e.faultString == 'SHUTDOWN_STATE':
logger.info('Supervisor in shutdown procedure, will check again later.') logger.info('Supervisor in shutdown procedure, will check again later.')
trynum += 1 trynum += 1
...@@ -86,12 +87,13 @@ def launchSupervisord(socket, configuration_file): ...@@ -86,12 +87,13 @@ def launchSupervisord(socket, configuration_file):
configuration_file + configuration_file +
"'] ; supervisor.supervisord.main()") "'] ; supervisor.supervisord.main()")
supervisord_popen = SlapPopen(invocation_list, supervisord_popen = SlapPopen(invocation_list,
env={}, env={},
executable=sys.executable, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) executable=sys.executable,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
result = supervisord_popen.communicate()[0] result = supervisord_popen.communicate()[0]
if supervisord_popen.returncode == 0: if supervisord_popen.returncode == 0:
log_message = 'Supervisord command invoked with: %s' % result logger.info('Supervisord command invoked with: %s' % result)
logger.info(log_message)
try: try:
default_timeout = socketlib.getdefaulttimeout() default_timeout = socketlib.getdefaulttimeout()
current_timeout = 1 current_timeout = 1
...@@ -108,7 +110,6 @@ def launchSupervisord(socket, configuration_file): ...@@ -108,7 +110,6 @@ def launchSupervisord(socket, configuration_file):
except Exception: except Exception:
current_timeout = 5 * trynum current_timeout = 5 * trynum
trynum += 1 trynum += 1
pass
else: else:
logger.info('Supervisord started correctly in try %s.' % trynum) logger.info('Supervisord started correctly in try %s.' % trynum)
return return
...@@ -129,32 +130,32 @@ Typical usage: ...@@ -129,32 +130,32 @@ Typical usage:
""".strip() """.strip()
parser = OptionParser(usage=usage) parser = OptionParser(usage=usage)
# Parses arguments # Parses arguments
if argument_tuple == (): if argument_tuple:
(argument_option_instance, argument_list) = parser.parse_args(list(argument_tuple))
else:
# No arguments given to entry point : we parse sys.argv. # No arguments given to entry point : we parse sys.argv.
(argument_option_instance, argument_list) = parser.parse_args() (argument_option_instance, argument_list) = parser.parse_args()
else:
(argument_option_instance, argument_list) = \ if not argument_list:
parser.parse_args(list(argument_tuple))
if len(argument_list) == 0:
parser.error("Configuration file is obligatory. Consult documentation by " parser.error("Configuration file is obligatory. Consult documentation by "
"calling with -h.") "calling with -h.")
configuration_file = argument_list[0] configuration_file = argument_list[0]
if not os.path.exists(configuration_file): if not os.path.exists(configuration_file):
parser.error("Could not read configuration file : %s" \ parser.error("Could not read configuration file : %s" % configuration_file)
% configuration_file)
slapgrid_configuration = ConfigParser.SafeConfigParser() slapgrid_configuration = ConfigParser.SafeConfigParser()
slapgrid_configuration.read(configuration_file) slapgrid_configuration.read(configuration_file)
# Merges the two dictionnaries # Merges the two dictionnaries
option_dict = dict(slapgrid_configuration.items("slapos")) option_dict = dict(slapgrid_configuration.items("slapos"))
# Supervisord configuration location # Supervisord configuration location
if not option_dict.get('supervisord_configuration_path'): option_dict.setdefault('supervisord_configuration_path',
option_dict['supervisord_configuration_path'] = \ os.path.join(option_dict['instance_root'], 'etc', 'supervisord.conf'))
os.path.join(option_dict['instance_root'], 'etc', 'supervisord.conf')
# Supervisord socket # Supervisord socket
if not option_dict.get('supervisord_socket'): option_dict.setdefault('supervisord_socket',
option_dict['supervisord_socket'] = \ os.path.join(option_dict['instance_root'], 'supervisord.socket'))
os.path.join(option_dict['instance_root'], 'supervisord.socket')
return option_dict, argument_list[1:] return option_dict, argument_list[1:]
...@@ -170,3 +171,4 @@ def supervisord(*argument_tuple): ...@@ -170,3 +171,4 @@ def supervisord(*argument_tuple):
option_dict, _ = getOptionDict(*argument_tuple) option_dict, _ = getOptionDict(*argument_tuple)
launchSupervisord(option_dict['supervisord_socket'], launchSupervisord(option_dict['supervisord_socket'],
option_dict['supervisord_configuration_path']) option_dict['supervisord_configuration_path'])
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: set et sts=2:
############################################################################## ##############################################################################
# #
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors. # Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
......
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