aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--main/asterisk.c38
2 files changed, 40 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 1f33c515e..b208f65b8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -79,6 +79,9 @@ CLI Changes
output to make debugging on busy systems much easier.
* New CLI commands "dialplan set extenpatternmatching true/false"
* New CLI command: "core set chanvar" to set a channel variable from the CLI.
+ * Added an easy way to execute Asterisk CLI commands at startup. Any commands
+ listed in the startup_commands file in the Asterisk configuration directory
+ will get executed.
SIP changes
-----------
diff --git a/main/asterisk.c b/main/asterisk.c
index 3ba00753c..3b3c2cb2a 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2664,7 +2664,7 @@ static void *canary_thread(void *unused)
stat(canary_filename, &canary_stat);
tv = ast_tvnow();
if (tv.tv_sec > canary_stat.st_mtime + 60) {
- ast_log(LOG_WARNING, "The canary is no more. He has ceased to be! He's expired and gone to meet his maker! He's a stiff! Bereft of life, he rests in peace. His metabolic processes are now history! He's off the twig! He's kicked the bucket. He's shuffled off his mortal coil, run down the curtain, and joined the bleeding choir invisibile!! THIS is an EX-CANARY. (Reducing priority)\n");
+ ast_log(LOG_WARNING, "The canary is no more. He has ceased to be! He's expired and gone to meet his maker! He's a stiff! Bereft of life, he rests in peace. His metabolic processes are now history! He's off the twig! He's kicked the bucket. He's shuffled off his mortal coil, run down the curtain, and joined the bleeding choir invisible!! THIS is an EX-CANARY. (Reducing priority)\n");
ast_set_priority(0);
pthread_exit(NULL);
}
@@ -2681,6 +2681,40 @@ static void canary_exit(void)
kill(canary_pid, SIGKILL);
}
+static void run_startup_commands(void)
+{
+ char filename[PATH_MAX];
+ char buf[256];
+ FILE *f;
+ int fd;
+
+ fd = open("/dev/null", O_RDWR);
+ if (fd < 0)
+ return;
+
+ snprintf(filename, sizeof(filename), "%s/startup_commands", ast_config_AST_CONFIG_DIR);
+
+ if (!(f = fopen(filename, "r"))) {
+ close(fd);
+ return;
+ }
+
+ while (fgets(buf, sizeof(buf), f)) {
+ size_t res = strlen(buf);
+
+ if (!res)
+ continue;
+
+ if (buf[res - 1] == '\n')
+ buf[res - 1] = '\0';
+
+ ast_cli_command(fd, buf);
+ }
+
+ fclose(f);
+ close(fd);
+}
+
int main(int argc, char *argv[])
{
int c;
@@ -3186,6 +3220,8 @@ int main(int argc, char *argv[])
ast_lastreloadtime = ast_startuptime = ast_tvnow();
ast_cli_register_multiple(cli_asterisk, sizeof(cli_asterisk) / sizeof(struct ast_cli_entry));
+ run_startup_commands();
+
if (ast_opt_console) {
/* Console stuff now... */
/* Register our quit function */