# Ari app deactivation

**URL:** <https://community.asterisk.org/t/ari-app-deactivation/101052>\
**Category:** Asterisk APIs\
**Created:** [February 19, 2024, 8:52am UTC](https://community.asterisk.org/t/ari-app-deactivation/101052 "2024-02-19T08:52:59Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![meirjdd](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@meirjdd](https://community.asterisk.org/u/meirjdd)\
**Post date:** [February 19, 2024, 8:52am UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/1 "2024-02-19T08:52:59Z")

</div>

Hi!

I am using nodejs, and at the end of a call, sometimes, the app I use closed with the websocket connection and sometimes not.  
How to force the app deactivation/shut down from the code please? I am using ari-client.

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![penguinpbx](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/penguinpbx/32/8856_2.png) [@penguinpbx](https://community.asterisk.org/u/penguinpbx)\
**Post date:** [March 6, 2024, 7:03pm UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/2 "2024-03-06T19:03:35Z")

</div>

There is a “hangup” function, highlighted in several of the [helpful node-ari-client examples](https://github.com/asterisk/node-ari-client/tree/master/examples), have you tried that ?

---

<div class="post-metadata">

**Author:** ![danishhafeez](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@danishhafeez](https://community.asterisk.org/u/danishhafeez)\
**Post date:** [March 7, 2024, 8:49am UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/3 "2024-03-07T08:49:39Z")

</div>

> [@meirjdd](#):
>
> Hi!
> 
> I am using nodejs, and at the end of a call, sometimes, the app I use closed with the websocket connection and sometimes not.  
> How to force the app deactivation/shut down from the code please? I am using ari-client.
> 
> Thanks a lot!

If you’re using the ari-client library in Node.js for Asterisk ARI integration and you want to forcibly terminate the application at the end of a call, you can achieve this by handling the appropriate events and then calling the `process.exit()` method to exit the Node.js process.

Here’s a general outline of how you can implement this:

```auto
const ari = require('ari-client');

// Connect to Asterisk
ari.connect('http://localhost:8088', 'username', 'password', (err, client) => {
  if (err) {
    console.error('Error connecting to ARI:', err);
    return;
  }

  // Handle StasisEnd event to detect when the call ends
  client.on('StasisEnd', (event, channel) => {
    // Check if this is the call you're interested in
    // For example, check the channel ID or any other relevant information

    // Perform any cleanup or logging operations here

    // Forcefully shut down the application
    process.exit(0);
  });

  // Start your ARI application logic here
});

// Handle process termination to gracefully disconnect from Asterisk
process.on('exit', () => {
  // Disconnect from Asterisk
  ari.disconnect();

  console.log('Application terminated');
});

```

In this code:

- We connect to Asterisk using `ari.connect()` method.
- We listen for the `StasisEnd` event, which is emitted when the call ends.
- Inside the event handler, you can perform any necessary cleanup or logging operations.
- Finally, we use `process.exit(0)` to forcibly terminate the Node.js process.

Make sure to replace `'http://localhost:8088'`, `'username'`, and `'password'` with your actual Asterisk ARI endpoint and credentials.

Best Regard  
Danish Hafeez | QA Assistant  
[ICTInnovations](https://www.ictinnovations.com)

---

<div class="post-metadata">

**Author:** ![meirjdd](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@meirjdd](https://community.asterisk.org/u/meirjdd)\
**Post date:** [March 10, 2024, 1:19pm UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/4 "2024-03-10T13:19:52Z")

</div>

Hi @penguinpbx

Thanks for your answer. I did not see the notification about it sorry for the late response.  
I use the hangup function.  
My problem is that at the end of a call I have  
`Deactivating Stasis app XXX`

and when I originate the next call :

```auto
Creating Stasis app 'New XXX'
 Shutting down application 'XXX'
 Destroying Stasis app XXX
    -- Remove stasis-XXX/h/1, registrar=res_stasis; con=stasis-XXX(0x7f372400afb0); con->root=0x7f372400b3a0
    -- Remove stasis-XXX/_./1, registrar=res_stasis; con=stasis-XXX(0x7f372400afb0); con->root=0x7f37240

```

To precise my answer, I am on the same process because the nodejs-code is called from a server.

---

<div class="post-metadata">

**Author:** ![meirjdd](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@meirjdd](https://community.asterisk.org/u/meirjdd)\
**Post date:** [March 10, 2024, 1:21pm UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/5 "2024-03-10T13:21:32Z")

</div>

Hi,

Thanks for your answer.  
Unfortunatly, this solution is not possible for me ( I used to work with process.exit() but now I can’t because my code is running on a server to be called from another one.

Thanks a lot

---

<div class="post-metadata">

**Author:** ![penguinpbx](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/penguinpbx/32/8856_2.png) [@penguinpbx](https://community.asterisk.org/u/penguinpbx)\
**Post date:** [March 12, 2024, 5:22pm UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/6 "2024-03-12T17:22:47Z")

</div>

> [@meirjdd](#):
>
> `_.`

That is very globby dial pattern. It may be matching more than you planned.

Unfortunately, the translation is making it difficult to understand the problem further. Posting some additional verbose logs, dial plan, etc., may help others debug further.

---

<div class="post-metadata">

**Author:** ![meirjdd](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@meirjdd](https://community.asterisk.org/u/meirjdd)\
**Post date:** [March 14, 2024, 3:23pm UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/7 "2024-03-14T15:23:38Z")

</div>

> [@penguinpbx](#):
>
> It may be matching more than you planned

What does it mean?

Thanks

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [March 14, 2024, 3:33pm UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/8 "2024-03-14T15:33:02Z")

</div>

It means “\_.”.

---

<div class="post-metadata">

**Author:** ![meirjdd](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@meirjdd](https://community.asterisk.org/u/meirjdd)\
**Post date:** [March 14, 2024, 3:41pm UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/9 "2024-03-14T15:41:59Z")

</div>

Sorry I don’t understand…

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [March 14, 2024, 4:07pm UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/10 "2024-03-14T16:07:49Z")

</div>

\_. matches everything that is is isn’t an empty string, so, in particular, it matches h, e, i, and other special extension names.

I’m not sure if it is treated literally, or as a pattern, here.

---

<div class="post-metadata">

**Author:** ![meirjdd](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@meirjdd](https://community.asterisk.org/u/meirjdd)\
**Post date:** [March 14, 2024, 6:18pm UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/11 "2024-03-14T18:18:14Z")

</div>

Thanks!  
There is a relation with the fact that the APP is destroyed only when a new call is done? One extension is called in the new APP and destroy the previous one by leaving?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [April 13, 2024, 6:18pm UTC](https://community.asterisk.org/t/ari-app-deactivation/101052/12 "2024-04-13T18:18:16Z")

</div>

Closed on April 13, 2024, 6:18pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
