def create_lock_file(lock_file_path): """Create the lock file. Arguments: lock_file_path path of the lock file """ f = open(lock_file_path, 'w') f.write(str(Common.getCurrentPid())) f.close()
def aozan_main(): """Aozan main method. """ # Define command line parser parser = OptionParser(usage='usage: ' + Globals.APP_NAME_LOWER_CASE + '.sh [options] conf_file') parser.add_option('-q', '--quiet', action='store_true', dest='quiet', default=False, help='quiet') parser.add_option('-v', '--version', action='store_true', dest='version', help='Aozan version') parser.add_option('-e', '--exit-code', action='store_true', dest='exit_code', help='Returns non zero exit code if a step fails') parser.add_option('-c', '--conf', action='store_true', dest='conf', help='Default Aozan configuration, loads before configuration file.') # Parse command line arguments (options, args) = parser.parse_args() # Print Aozan current version if options.version: print Globals.WELCOME_MSG sys.exit(0) # Print default configuration option if options.conf: print common.print_default_configuration() sys.exit(0) # If no argument print usage if len(args) < 1: parser.print_help() sys.exit(1) # Create configuration object conf = LinkedHashMap() # Set the default value in the configuration object common.set_default_conf(conf) # Use default (US) locale Locale.setDefault(Globals.DEFAULT_LOCALE) # Check if OS is Linux if not SystemUtils.isLinux(): sys.stderr.write('ERROR: Aozan can not be executed. Operating system is not Linux\n') sys.exit(1) # Check if configuration file exists conf_file = args[0] if not os.path.isfile(conf_file): sys.stderr.write('ERROR: Aozan can not be executed. Configuration file is missing: ' + \ conf_file + '\n') sys.exit(1) # Load Aozan conf file common.load_conf(conf, conf_file) # End of Aozan if aozan is not enable if common.is_conf_value_defined(AOZAN_ENABLE_KEY, 'false', conf): sys.exit(0) # Init logger try: Common.initLogger(conf[AOZAN_LOG_PATH_KEY], conf[AOZAN_LOG_LEVEL_KEY]) except AozanException, exp: common.exception_msg(exp, conf)
# Create lock file create_lock_file(lock_file_path) # Launch steps result = launch_steps(conf) # Remove lock file delete_lock_file(lock_file_path) # TODO remove *.lasterr files if something_to_do: common.log('INFO', 'Ending Aozan', conf) # Cancel logger, in case not be cancel properly Common.cancelLogger() if not result and options.exit_code: sys.exit(1) except: exception_error(None, '', conf) common.log('INFO', 'Ending Aozan', conf) # Remove lock file delete_lock_file(lock_file_path) # Cancel logger, in case not be cancel properly Common.cancelLogger() sys.exit(1)