1 | const fs = require('fs');
|
2 | const path = require('path');
|
3 | const cluster = require("cluster");
|
4 |
|
5 | module.exports = () => {
|
6 |
|
7 | if(Config("_server").restart) new fs._watcher(path.join(_vap.server)).watch(restart);
|
8 |
|
9 | function restart (event,pathToIt) {
|
10 | if(!pathToIt.endsWith(".js")) return;
|
11 | consol.warning(" # Application files edit occurred");
|
12 | consol.info(` - File "${pathToIt.substr(pathToIt.lastIndexOf("/")+1).substr(pathToIt.lastIndexOf("\\")+1)}" has been ${event}`);
|
13 | consol.info(" - Now Killing all workers and creating new ones");
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | let saved = 0;
|
20 | for (let id in cluster.workers) {
|
21 | if(!saved && Object.keys(cluster.workers).length > 1) {
|
22 | saved = id;
|
23 | continue;
|
24 | }
|
25 | cluster.workers[id].send("die");
|
26 | }
|
27 | cluster.on('listening', (worker, address) => {
|
28 | if(saved && Object.keys(cluster.workers).length > 1) {
|
29 | cluster.workers[saved].send("die");
|
30 | saved = 0;
|
31 | }
|
32 | });
|
33 | }
|
34 | }; |
\ | No newline at end of file |