[Home]

Summary:ASTERISK-02816: [patch] add -e option to exec something after bootup
Reporter:k3v (k3v)Labels:
Date Opened:2004-11-15 12:23:10.000-0600Date Closed:2011-06-07 14:04:43
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) asterisk-system-on-booted.patch.txt
Description:This -e option runs an arbitrary shell command after asterisk is fully booted, or on restart.

****** ADDITIONAL INFORMATION ******

I needed to reconcile some database entries to queues, and send a UDP message to our monitoring bots after restart.  This seemed like the most flexible way to allow others to do whatever they might need.  Disclaimer on file.
Comments:By: k3v (k3v) 2004-11-15 12:25:28.000-0600

This is how I'm using it:  "asterisk -ce /etc/asterisk/perl/queue-restore.pl"

#!/usr/bin/perl -w

my @agentson;
my %valid;

print "*** Restoring queue members after restart.  This will make a lot of noise.\n";

open (IN, "/usr/sbin/asterisk -rx 'database show'|");
while (<IN>) {
       my $line = $_;
       chomp $line;
       if ($line =~ /available\/(\d+)/) {
               push @agentson, $1;
       }
       elsif ($line =~ /valid\/(\d+)\s+:\s(\S+)/) {
               $valid{$1} = $2;
       }
}
close IN;

foreach my $agent (@agentson) {
       foreach my $queue (split /\./, $valid{$agent}) {
               system("/usr/sbin/asterisk -rx 'add queue member Local/$agent\@agent to $queue'");
       }
}

By: Olle Johansson (oej) 2004-11-15 13:19:07.000-0600

Wouldn't it be better to call a CLI script - a more general solution. If we start "asterisk -e" we run asterisk.rc where you could add an "!perl myfile.pl" command.  

Thinking about it, it would certainly be a better and more flexible solution.

By: Clod Patry (junky) 2004-11-15 13:36:48.000-0600

I understand his point here.
Maybe he wants to start asterisk, then run a specific script each time he starts asterisk. So he saves time starting that script at the same time.


Imoh, i think this is interesting, but i would call it with s option (for shell), but i've no decision related to this.

By: Clod Patry (junky) 2004-11-15 17:34:52.000-0600

i did a asterisk -cvvvve 'top'
and even if you do a ctrl-c, the top is never killed.
Dunno if that could be solved.

That doesn't work for -r option?
i did a
# asterisk -rvvvvve '/home/cpatry/time.pl
and this is my output:
neo:/usr/src/asterisk# asterisk -rvvvvve '/var/lib/asterisk/agi-bin/time.pl'
 == Parsing '/etc/asterisk/asterisk.conf': Found
 == Parsing '/etc/asterisk/extconfig.conf': Found
Asterisk CVS-HEAD-11/12/04-17:36:39, Copyright (C) 1999-2004 Digium.
Written by Mark Spencer <markster@digium.com>
=========================================================================
Connected to Asterisk CVS-HEAD-11/12/04-17:36:39 currently running on neo (pid = 15912)
Verbosity was 1 and is now 5
neo*CLI>


there's nothing related to my time.pl there.
and this is my time.pl script:
neo:/usr/src/asterisk# cat /home/cpatry/time.pl
#!/usr/bin/perl -w

print time(). "\n";
neo:/usr/src/asterisk#

I know all this could be run via:
*CLI> !/home/cpatry/time.pl
1100561342
*CLI>


I was just testing with different things.

By: twisted (twisted) 2004-11-15 22:59:15.000-0600

My two cents:

I agree, this acutually should spawn off .asteriskrc if nothing else.  Also, this should *NOT* function from the remote console, only from the console session (-vvvvvcg).

By: k3v (k3v) 2004-11-17 01:48:57.000-0600

My goal here is to 'do something extra' when asterisk is fully initialized, not simply to run stuff I could do in a shell script anyway.  I think OEJ hit it right on the head.  Instead, I'll have it parse from asterisk.rc in $(ASTETCDIR), with a list of cli commands.  Do we think -e should still be required, or just load that rc if it exists?  

This is be something that would run without a requirement of -c, since -r should not invoke it.  It executes just after "Asterisk Ready." is printed.  The patch doesn't show enough of the surrounding code to indicate that without applying it.

I'm not as embedded with the * source as some of you.  Is there already some facility in place to parse and execute cli commands from a file?  Not that it's not simple enough to do so, but no sense in reinventing the wheel.

By: Kevin P. Fleming (kpfleming) 2004-11-17 07:37:03.000-0600

I know it would be kind of "odd", but I had been considering something like (in extensions.conf):

[general]
startup = startup-context

[startup-context]
exten => s,1,do_stuff_here
exten => s,n,do_more_stuff_here

The idea here is that when * is ready to print "Asterisk Ready", it would create a dummy channel and execute extension "s" priority 1 in "startup-context". This would then allow for any normal * apps to be called at startup time, prior to allowing any "real" channels to be created.

Personally, I would prefer this method over an external rc file, especially since if the commands to be executed are all * apps then it will be much more efficient as well.

I have not yet looked at the * code to see how difficult this would be to implement, but it's on my list of things to do :-)

By: k3v (k3v) 2004-11-17 09:17:34.000-0600

That was actually what I was looking for initially.  I'll look into that option as well while I'm redoing this patch today.

By: Olle Johansson (oej) 2004-11-19 01:27:03.000-0600

Maybe this would work:
* If asterisk.rc exists, execute commands in that file - ONLY at server startup, not at remote console
* Add an option to execute a command file from a remote console with an option, an enhanced "-rx"

By: k3v (k3v) 2004-11-24 20:43:05.000-0600

I've been busy working out other, more pressing issues.  I'll get back on this following the holiday.

By: Brian West (bkw918) 2004-11-30 00:16:00.000-0600

This doesn't give me the warm and fuzzy feeling...  If you think you can talk to kram and come up with something that could fly?