Checking asterisk status (on gracefully shutdown)

Any external command (or using asterisk -x command) to see if currently asterisk is doing a “gracefully” shutdown?

I am writing a bash scrip and in that scrip I need to know if asterisk is currently doing a gracefully shutdown.

I am running Asterisk 11

Thank you!

Howdy,

Probably:
wiki.asterisk.org/wiki/display/ … t_Shutdown

will help you.

A graceful shutdown is a clean shutdown.

He’s not asking how to do one, but rather how to detect if one is in progress.

He really needs to explain why he wants to this and why he doesn’t know that one has been initiated. If you know one has been initiated, simply checking for a process number change will normally work, and checking the time on the .ctl file will definitely work.

thx David, again, for the reply.

The reason I want this is a little bit complicated. So here is the system I have.

  1. I have inbound Opensips that load balance call to several asterisk server (asterisk 11)
  2. Each asterisk server then send the call (that came from the inbound opensip) to a outbound opensips (asterisk and outbound opensips is 1:1)

So the other day I ran into issue where the outbound opensips went down thus all the call on that asterisk was failing. But the inbound opensips does not know the outbound opensips went down, thus call was keep getting distributed to that asterisk (which is bad).

Therefore, I needed a way to have asterisk server signal the inbound opensips to not to send call to it if the outbound opensips is down.

So (with the help with a forum member), I start write bash script where the bash scrip will execute asterisk -x ‘sip show peer blah’ and with that response, if the peer show down, it will execute a python script which will send a xmlrpc call to opensips to mark the asterisk node as “down”. When the peer (the opensip) comes back online, it will send a “up” message to inbound opensips.

BUT the issue now is, during “gracefully shut down”, and that the script runs every 3 minutes, it will keep telling opensips to turn the node “up” when it is mark as “down”.

Just quickly explain how opensips detect asterisk as “up” or “down”. Once asterisk IP gets added into opensips load balancer table, opensips will constantly send a SIP OPTION message to query if the asterisk is up. Once asterisk is in the process of gracefully shut down, opensips will mark the node down because of the negative result it gets from the asterisk’s SIP OPTION query. So, now with the job running, it will tell opensips to mark the node “up” and then 10 seconds later (when opensips send the OPTION query), opensips will mark it down again, and the process repeats until asterisk shut down.

So I really need a way where in my bash scrip, I can do some sort of “function call” to see what is the status of asterisk. If is in the process of gracefully shut down, DO NOT send “up” message to opensips.

Thank you!

The two method you described, and again, I am no linux guru, can you simply give me a few line of bash script code to accomplish what you said above (where you said you can check the .ctl time or the process id)?

Thank you for all your help!

Howdy,

I’m missing something?

I pointed to the Manager Event not an Action. The event fires when Asterisk is told to shutdown.

So if I’m in the Asterisk CLI and I perform:

core stop gracefully

And I’m connected via AMI, using some script or other that I’ve written, then I’ll see:

Event: Shutdown
Restart: False
Shutdown: Cleanly

Cheers

Apologies for misreading that, but he seems to know when the process starts. He want to test to see if it is still in progress (i.e whether there has been a subsequent restart).