Daemon initiated by exec node stops with Node-red restart


#1

Node-Red is on raspbian- stretch instance. OpenVpn daemon on the same instance gets initiated successfully by an exec node using the below command.

sudo openvpn --config /etc/openvpn/client.ovpn --daemon

When working with a standard ssh terminal, this command ensures that this daemon continues to work in the background even the ssh terminal is closed after executing the command.

If node-red is stopped after executing the daemon with exec node, the daemon also stops?

I need help on how to make this execution persistent?


#2

The RaspberryPi page in the docs details how to start Node-RED as a service which makes the execution persistent

https://nodered.org/docs/hardware/raspberrypi


#3

Thank you for your reply.
I'm sorry. I wasn't clear enough with my question.
Nodered.service is already persistent against reboots. I need the daemon executed by the Node_red exec node to be persistent even after a Node-Red stop. (By the way Node-Red stop is not caused by a any hardware shutdown)
Node-Red utilizing the exec node executes the above command perfectly and openvpn daemon starts to work. No problem. However the daemon stops abruptly when node-red is stopped.

When I execute the above command from a terminal, it works. Daemon doesn't stop even if I close the terminal.


#4

possible workaround: perhaps have the exec node invoke a screen session to pseud-encapsulate the launch of the daemon so it isn't dependent on node-red's shell session?


#5

I'll try putting the command in a bash script and execute this script from exec node. Maybe that will do the trick. :+1:


#6

Are you using "spawn" mode in your exec node? (not sure if that will help, however)

Also, I've not tried it, but there is another related node in the flows library, called node-red-node-daemon -- although I would think that a node-red server restart would still lose its connection to any process it started...


#7

when the Node-RED exit it closes the flow - which in this case (and for the daemon node) calls kill on the child process. If you need it to run independent of Node-RED you may be able to call it via another shell command (as suggested above) - or just start it outside of Node-RED altogether.


#8

@shrickus I'm not using "spawn" mode. I tried "node-red-node-daemon" but it didn't help.

@dceejay I tried the bash script option (put the command in a bash script and execute it via exec node). I also tried using "nohub command &" to detach the process. But these didn't work out. I'll find another way to start it outside of Node-RED as you suggested.

Thanks everyone for your replies.