How can I unmount a node?

Is there a generally accepted means of deamonization (and, of course, late communication via signals or some abstraction on it) node script?

That is, is there a node equivalent:

if (fork()) // parent process, die exit(1); // we're a daemon 
+4
source share
4 answers

Node Web Development

The following is a list of ways to run Node as a background daemon on different platforms:

  • nodejs-autorestart manages a Linux Node instance that uses Upstart (Ubuntu, Debian, etc.).
  • fugue looks at the Node server, restarting it if it works.
  • forever is a small Node script command line that ensures that the script will run forever.
  • node-init is a Node script that turns your Node application into an LSB-compatible init script, LSB is a Linux compatibility specification.
+1
source

Node has no built-in way to do this. Take a look at Writing a daemon in JavaScript with Node.js for one implementation (warning: this is relatively old and Node - I have not tested it. :)

0
source

Upstart works well for me, although I have a problem when I serve https. Here is the tutorial that I used:

http://kevin.vanzonneveld.net/techblog/article/run_nodejs_as_a_service_on_ubuntu_karmic/

You can use the node process object to send / process signals.

0
source

As others have pointed out, there really is no way to do this directly in Node. You really need to run it using foreverjs . The reason you need to run it using the monitor, as forever, is because the error caused by your code often leads to the completion of the entire Node process for exiting and exiting. The monitor will search for it and immediately restart the process.

It is also important to note that when you restart the process, your server will not respond to the request, so plan ahead if you expect this to be a problem and make sure that you have several server processes running under load balancer.

0
source

Source: https://habr.com/ru/post/1389006/


All Articles