John Marvin wrote:
Larry Alkoff wrote:
As stated in the original post, when I entter the IP with an editor directly into sip.conf calls work just fine but I am looking for a way to have that done _automatically_.

The Asterisk - Future of Telephony book says it is possible for Asterisk to access a Linux environment variable containing the IP information in the form of "${ENV{variable}}.

It doesn't seem to work.  I am asking how to make it work.


Actually, I don't think you read his response carefully enough. He was giving you a method of doing it automatically.

But first, lets dismiss the environment variable solution. I haven't played with using environment variables in Asterisk, so I can't help you there. But I do know about environment variables in general, and you cannot use them to solve your problem. Environment variables are not "global", i.e. if you change one it does not effect the value in all currently running programs. The "environment" (all of the environment variables and their values) is inherited from the parent process (it is passed in by the kernel on the new processes stack when the process first starts). After that, only the process itself can change its own values in order to pass on a changed value to a child (but again, only when that child process is started, i.e. a parent cannot affect the environment of an already running child process). In summary, you can't change the values of Asterisk's environment variables after Asterisk has already started. The values that Asterisk sees are the values that it inherited from its parent process, i.e. most likely the rc scripts that started Asterisk when you first booted the machine.

Now, back to the solution proposed by Brad. He was in effect proposing that you dynamically change sip.conf. However, parsing a rewriting sip.conf automatically is kind of ugly, but luckily Asterisk supports #include. So, he suggested that you can periodically generate a file with a single line in it, i.e. "externip=xx.xx.xx.xx" and then use #include in your sip.conf to include it (i.e. sip.conf doesn't have to ever change). The final part of the solution is to make Asterisk reread sip.conf (and the included dynamically created file at the same time). You can do that with:

    asterisk -rx "sip reload"

which you can put into the same cron job that you currently are using to refresh /etc/myip.

John

John you are quite correct about Brad's solution and I have to thank you both. I thought again about Brad's post last night in bed - where I do my best work <g>.

The #include route is indeed a way to go.

In the meantime, I've found more about externhost which was implemented in Asterisk 1.20+.

I put a line in sip.conf of
externhost=myhost.dyndns.org
with a refresh of 6 hours against the default of 10 seconds ala
externrefresh=21600

This seems to be working nicely but, if there are problems, I'll change to #include.

You are also correct that environmental variables will not refresh until the Asterisk shell is reloaded - hopefully not often!

It would still be nice to be able to access shell variables from within the CLI and particularly frustrating since the "Asterisk - Future of Telephony" mentions a specific method on page 92. Perhaps they got the syntax wrong. I certainly would like a better connection between the shell and CLI.

Thanks for your explanation and I apologize for not realizing that Brad's suggestion was spot on.

Larry


--
Larry Alkoff N2LA - Austin TX
Using Thunderbird on Linux
_______________________________________________
--Bandwidth and Colocation provided by Easynews.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to