Running a child process with Kibana

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

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?

Hi @Kvin,

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

Thanks,
Chris

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.

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

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

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

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

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

@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.

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