# Running a child process with Kibana

**URL:** <https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842>\
**Category:** Kibana\
**Created:** [October 13, 2017, 7:24am UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842 "2017-10-13T07:24:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kvin](https://avatars.discourse-cdn.com/v4/letter/k/e99b99/32.png) [@Kvin](https://discuss.elastic.co/u/Kvin)\
**Post date:** [October 13, 2017, 7:24am UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842/1 "2017-10-13T07:24:47Z")

</div>

Hi!

We are writing a script for a Kibana plugin in node.js. This script at some point starts a child process. We would like to start this process in a "nohup way," so when we stop Kibana, this process would still be running in the background.

Whatever we do, we cannot make this happen.

Our current code is:

```
const spawn = require('child_process').spawn;

const gen = spawn('nohup', ['/some/shell/script.sh', 'param1', 'param2', '&'], {
  cwd: '/folder/where/we/execute/the/command',
  detached: true,
  stdio: 'ignore'
});

gen.unref();

```

We were following this: [https://nodejs.org/api/child\_process.html#child\_process\_options\_detached](https://nodejs.org/api/child_process.html#child_process_options_detached)

I would like to note that we can start the process and it runs perfectly fine. The problem is that it gets terminated with the Kibana shut down.

Could someone, please, give us some hint, where to look, or let us know, what we are doing wrong?

---

<div class="post-metadata">

**Author:** ![chrisronline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chrisronline/32/28230_2.png) [@chrisronline](https://discuss.elastic.co/u/chrisronline)\
**Post date:** [October 19, 2017, 8:59am UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842/2 "2017-10-19T08:59:44Z")

</div>

Hi @Kvin,

Is the child process interacting with the main kibana process in any way?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![Kvin](https://avatars.discourse-cdn.com/v4/letter/k/e99b99/32.png) [@Kvin](https://discuss.elastic.co/u/Kvin)\
**Post date:** [October 19, 2017, 9:11am UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842/3 "2017-10-19T09:11:21Z")

</div>

Hi @chrisronline!

May I ask what do you mean by interacting? The child process just starts a custom shell script which does nothing with Kibana. I can even start it "by hand" whilst Kibana is offline and it would still get the job done.

---

<div class="post-metadata">

**Author:** ![chrisronline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chrisronline/32/28230_2.png) [@chrisronline](https://discuss.elastic.co/u/chrisronline)\
**Post date:** [October 19, 2017, 9:14am UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842/4 "2017-10-19T09:14:17Z")

</div>

Hi @Kvin,

I saw this note in the node docs:

> unless there is an established IPC channel between the child and parent.

I just wanted to make sure this wasn't the case which might be related to the child process termination.

Since that's not the case, I'll look more into it and let you know.

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![chrisronline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chrisronline/32/28230_2.png) [@chrisronline](https://discuss.elastic.co/u/chrisronline)\
**Post date:** [October 19, 2017, 12:38pm UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842/5 "2017-10-19T12:38:20Z")

</div>

Hi @Kvin,

I tested this and didn't see an issue. The process still runs after shutting Kibana down. If I set `detached:false`, the child process quit when Kibana quit so that works as expected.

What version of node are you running? What OS?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![Kvin](https://avatars.discourse-cdn.com/v4/letter/k/e99b99/32.png) [@Kvin](https://discuss.elastic.co/u/Kvin)\
**Post date:** [November 7, 2017, 10:48am UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842/6 "2017-11-07T10:48:24Z")

</div>

Hi @chrisronline!

We are using the node which was packed with the 5.2.0 Kibana. This means that our node version is 6.9.0. We are using Red Hat Enterprise Linux Server release 7.4.

Sorry for the late response.  
Kind regards

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [November 7, 2017, 2:45pm UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842/7 "2017-11-07T14:45:29Z")

</div>

Can you verify kibana and your script are in different sessions and process groups using "ps -e -o pid,pgrp,session,ppid,cmd"?

---

<div class="post-metadata">

**Author:** ![chrisronline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chrisronline/32/28230_2.png) [@chrisronline](https://discuss.elastic.co/u/chrisronline)\
**Post date:** [November 17, 2017, 3:53pm UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842/8 "2017-11-17T15:53:13Z")

</div>

@Kvin Sorry for the late response. Did you get any traction on this?

---

<div class="post-metadata">

**Author:** ![Kvin](https://avatars.discourse-cdn.com/v4/letter/k/e99b99/32.png) [@Kvin](https://discuss.elastic.co/u/Kvin)\
**Post date:** [November 27, 2017, 2:28pm UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842/9 "2017-11-27T14:28:16Z")

</div>

@Badger Thank you for the tip!

If I use spawn (the code I originally posted), I get the following:

```
17749 17749 17749 1 /usr/share/kibana/bin/../node/bin/node --no-warnings /usr/share/kibana/bin/../src/cli -c /etc/kibana/kibana.yml
18405 18396 18396 1 /bin/bash /path/to/shell/script.sh param1 param2
18415 18396 18396 18405 /bin/bash /path/to/shell/script.sh param1 param2

```

If I use exec instead of spawn, I get the following:

```
20881 20881 20881 1 /usr/share/kibana/bin/../node/bin/node --no-warnings /usr/share/kibana/bin/../src/cli -c /etc/kibana/kibana.yml
21084 20881 20881 1 /bin/bash /path/to/shell/script.sh param1 param2
21087 20881 20881 21084 /bin/bash /path/to/shell/script.sh param1 param2

```

However in both cases, if I stop Kibana, the child processes die with it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 25, 2017, 2:28pm UTC](https://discuss.elastic.co/t/running-a-child-process-with-kibana/103842/10 "2017-12-25T14:28:24Z")

</div>

Closed on December 25, 2017, 2:28pm UTC

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