util/startup.lua
changeset 10938 b4daa697a7ea
parent 10655 1196f1e8d178
child 10940 d770435f0f84
equal deleted inserted replaced
10937:f59bc81245b3 10938:b4daa697a7ea
    11 local config_warnings;
    11 local config_warnings;
    12 
    12 
    13 local dependencies = require "util.dependencies";
    13 local dependencies = require "util.dependencies";
    14 
    14 
    15 local original_logging_config;
    15 local original_logging_config;
       
    16 
       
    17 local default_gc_params = { mode = "incremental", threshold = 105, speed = 250 };
    16 
    18 
    17 local short_params = { D = "daemonize", F = "no-daemonize" };
    19 local short_params = { D = "daemonize", F = "no-daemonize" };
    18 local value_params = { config = true };
    20 local value_params = { config = true };
    19 
    21 
    20 function startup.parse_args()
    22 function startup.parse_args()
   519 		print("");
   521 		print("");
   520 		os.exit(1);
   522 		os.exit(1);
   521 	end
   523 	end
   522 end
   524 end
   523 
   525 
       
   526 function startup.init_gc()
       
   527 	-- Apply garbage collector settings from the config file
       
   528 	local gc = require "util.gc";
       
   529 	local gc_settings = config.get("*", "gc") or { mode = default_gc_params.mode };
       
   530 
       
   531 	local ok, err = gc.configure(gc_settings, default_gc_params);
       
   532 	if not ok then
       
   533 		log("error", "Failed to apply GC configuration: %s", err);
       
   534 		return nil, err;
       
   535 	end
       
   536 	return true;
       
   537 end
       
   538 
   524 function startup.make_host(hostname)
   539 function startup.make_host(hostname)
   525 	return {
   540 	return {
   526 		type = "local",
   541 		type = "local",
   527 		events = prosody.events,
   542 		events = prosody.events,
   528 		modules = {},
   543 		modules = {},
   549 	startup.parse_args();
   564 	startup.parse_args();
   550 	startup.init_global_state();
   565 	startup.init_global_state();
   551 	startup.read_config();
   566 	startup.read_config();
   552 	startup.force_console_logging();
   567 	startup.force_console_logging();
   553 	startup.init_logging();
   568 	startup.init_logging();
       
   569 	startup.init_gc();
   554 	startup.setup_plugindir();
   570 	startup.setup_plugindir();
   555 	-- startup.setup_plugin_install_path();
   571 	-- startup.setup_plugin_install_path();
   556 	startup.setup_datadir();
   572 	startup.setup_datadir();
   557 	startup.chdir();
   573 	startup.chdir();
   558 	startup.read_version();
   574 	startup.read_version();
   571 	prosody.process_type = "prosody";
   587 	prosody.process_type = "prosody";
   572 	startup.parse_args();
   588 	startup.parse_args();
   573 	startup.init_global_state();
   589 	startup.init_global_state();
   574 	startup.read_config();
   590 	startup.read_config();
   575 	startup.init_logging();
   591 	startup.init_logging();
       
   592 	startup.init_gc();
   576 	startup.sanity_check();
   593 	startup.sanity_check();
   577 	startup.sandbox_require();
   594 	startup.sandbox_require();
   578 	startup.set_function_metatable();
   595 	startup.set_function_metatable();
   579 	startup.check_dependencies();
   596 	startup.check_dependencies();
   580 	startup.init_logging();
   597 	startup.init_logging();