diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-01-17 00:05:13 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-01-17 00:05:13 +0000 |
commit | 8ff8275976d94c916e9eb6807aeb60e461c6c45d (patch) | |
tree | cabd950041b10ac3d1014e2c257b8820d5b1df7d | |
parent | 7a5f69431abc8dfc73c610358d633279cf932990 (diff) |
Add support for an easy way to automatically execute some Asterisk CLI commands
immediately at startup. Any commands in the startup_commands file in the Asterisk
config diretory will get executed.
(closes issue #11781)
Reported by: jamesgolovich
Patches:
asterisk-startupcmds.diff.txt uploaded by jamesgolovich (license 176)
-- With some changes by me.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@98986 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | main/asterisk.c | 38 |
2 files changed, 40 insertions, 1 deletions
@@ -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 */ |