I’ve got a cluster of asterisks that i’d like to scale in and out based on load. To drain these i was planning on performing a graceful shutdown, have kamailio detect that it’s down and then just wait until there are no more active calls. This mostly works.
Our normal call flow is that an inbound caller hits our ARI application, it looks up a destination, calls that destination and bridges the two calls. But if the shutdown is initiated after the inbound call but before the outbound call that fails with “Channel allocation failed: Refusing due to active shutdown”
Is there a way to be in graceful shutdown but still allow outbound calls from asterisk?
jcolp
April 21, 2026, 1:28pm
2
No. It is explicitly written to disallow all channel creation.
Thanks for the quick clarification.
Is there any way to change a sip option response from asterisk on the fly, so that i can still get a 5xx response back to kamailio but not do the graceful shutdown?
I could disable the ast on the kamailio side but i’d prefer if the asterisk could take the decision to ‘die’ independently.
jcolp
April 21, 2026, 1:51pm
4
You can’t explicitly control OPTIONS like that. This was merged last week, though:
master ← danieldonoghue:pjsip-maint
opened 03:13PM - 10 Mar 26 UTC
Introduces res_pjsip_maintenance, a loadable module that allows
operators to pl… ace individual PJSIP endpoints into maintenance mode
at runtime without unregistering or disabling them.
While an endpoint is in maintenance mode:
* New inbound INVITE and SUBSCRIBE dialogs are rejected with
503 Service Unavailable and a Retry-After: 300 header.
* In-progress dialogs (re-INVITE, UPDATE, BYE, etc.) are
unaffected and complete normally.
* Outbound originations via Dial() or ARI originate are refused
before any SIP session is created.
State is held in-memory only and is cleared on module unload
or Asterisk restart.
This module was developed with AI assistance (Claude). All code
has been reviewed and tested by the author, who takes full
responsibility for the submission.
CLI interface:
pjsip set maintenance <on|off> <endpoint|all>
pjsip show maintenance [endpoint]
AMI interface:
Action: PJSIPSetMaintenance
Endpoint: <name>|all
State: on|off
Action: PJSIPShowMaintenance
Endpoint: <name> (optional; omit to list all)
Emits PJSIPMaintenanceStatus events per result, followed by
PJSIPMaintenanceStatusComplete. State changes also emit an
unsolicited PJSIPMaintenanceStatus event.
To support outbound blocking, a new session_create callback is
added to ast_sip_session_supplement. Supplements that set this
callback are invoked at the start of ast_sip_session_create_outgoing()
in res_pjsip_session, before any dialog or invite session resources
are allocated. res_pjsip_maintenance registers itself as a session
supplement and uses this callback to gate outbound session creation
on a per-endpoint basis.
MODULEINFO:
<depend>pjproject</depend>
<depend>res_pjsip</depend>
<depend>res_pjsip_session</depend>
UserNote: New module res_pjsip_maintenance adds runtime maintenance
mode for PJSIP endpoints. Use "pjsip set maintenance <on|off>
<endpoint|all>" to enable or disable, and "pjsip show maintenance"
to list affected endpoints. AMI actions PJSIPSetMaintenance and
PJSIPShowMaintenance provide programmatic access. No configuration
file changes required.
DeveloperNote: ast_sip_session_supplement gains a new optional
callback - int (*session_create)(struct ast_sip_endpoint *endpoint,
const char *destination). It is called from the global supplement
list (not per-session) at the start of ast_sip_session_create_outgoing()
via ast_sip_session_check_supplement_create(). Returning non-zero
blocks the outgoing session. Modules that need to gate outbound
SIP session creation should register a supplement with this callback
set rather than hooking into chan_pjsip directly.
Would you look at that. At a glance it’s what i need. Thanks!