; Any commands listed in this section will get automatically executed
; when Asterisk starts as a daemon or foreground process (-c).
;
+; Commands with a value of "pre-init" will run just after the logger
+; is initialized but before all other core and module initialization.
+;
+; Commands with a value of "pre-module" will run just after core
+; initialization is done but before module initialization.
+;
+; These two values can be used for things like enabling debugging on
+; specific modules before they're loaded so you can see debug messages
+; generated during their initialization. Of course you can't run
+; commands from modules that haven't loaded yet.
+
+; Commands with a value of "yes" or "fully-booted" will run after all
+; core and module initialization is completed and just before
+; "Asterisk Ready" is printed on the console.
+;
+;core set debug 3 channels.c = pre-init
+;core set debug 3 res_pjsip.so = pre-module
;core set verbose 3 = yes
-;core set debug 1 = yes
}
}
+enum startup_commands_phase {
+ STARTUP_COMMANDS_PRE_INIT = 0,
+ STARTUP_COMMANDS_PRE_MODULE,
+ STARTUP_COMMANDS_FULLY_BOOTED
+};
+
+static const char *startup_commands_phase_str[] = {
+ "pre-init",
+ "pre-module",
+ "fully-booted,yes,true,y,t,1,on"
+};
+
/* Execute CLI commands on startup. Run by main() thread. */
-static void run_startup_commands(void)
+static void run_startup_commands(enum startup_commands_phase phase)
{
int fd;
struct ast_config *cfg;
}
for (v = ast_variable_browse(cfg, "startup_commands"); v; v = v->next) {
- if (ast_true(v->value))
+ char *value = ast_str_to_lower(ast_strdupa(v->value));
+ if (ast_in_delimited_string(value, startup_commands_phase_str[phase], ',')) {
ast_cli_command(fd, v->name);
+ }
}
close(fd);
threadstorage_init();
check_init(init_logger(), "Logger");
+ run_startup_commands(STARTUP_COMMANDS_PRE_INIT);
+
check_init(ast_rtp_engine_init(), "RTP Engine");
ast_autoservice_init();
check_init(ast_local_init(), "Local Proxy Channel Driver");
check_init(ast_refer_init(), "Refer API");
+ run_startup_commands(STARTUP_COMMANDS_PRE_MODULE);
+
/* We should avoid most config loads before this point as they can't use realtime. */
check_init(load_modules(), "Module");
ast_cli_register_multiple(cli_asterisk, ARRAY_LEN(cli_asterisk));
ast_register_cleanup(main_atexit);
- run_startup_commands();
+ run_startup_commands(STARTUP_COMMANDS_FULLY_BOOTED);
ast_sd_notify("READY=1");
ast_verb(0, COLORIZE_FMT "\n", COLORIZE(COLOR_BRGREEN, 0, "Asterisk Ready."));