@colyseus/tools 0.15.1 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/post-deploy.js +11 -53
- package/system-boot.js +55 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colyseus/tools",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "Colyseus Tools for Production",
|
|
5
5
|
"input": "./src/index.ts",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"start": "ts-node-dev example/app.ts"
|
|
11
11
|
},
|
|
12
12
|
"bin": {
|
|
13
|
+
"colyseus-system-boot": "system-boot.js",
|
|
13
14
|
"colyseus-post-deploy": "post-deploy.js"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
|
@@ -47,5 +48,5 @@
|
|
|
47
48
|
"publishConfig": {
|
|
48
49
|
"access": "public"
|
|
49
50
|
},
|
|
50
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "810b5a4f8f849efb4d06226e54e8cad7aa72927a"
|
|
51
52
|
}
|
package/post-deploy.js
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
const pm2 = require('pm2');
|
|
3
3
|
const os = require('os');
|
|
4
4
|
const fs = require('fs');
|
|
5
|
-
const { exec } = require('child_process');
|
|
6
5
|
|
|
7
6
|
const opts = { env: process.env.NODE_ENV || "production" };
|
|
8
7
|
const maxCPU = os.cpus().length;
|
|
9
8
|
|
|
10
9
|
const NGINX_SERVERS_CONFIG_FILE = '/etc/nginx/colyseus_servers.conf';
|
|
11
|
-
const NGINX_LIMITS_CONFIG_FILE = '/etc/nginx/colyseus_limits.conf';
|
|
12
10
|
|
|
13
11
|
pm2.list(function(err, apps) {
|
|
14
12
|
bailOnErr(err);
|
|
@@ -36,30 +34,24 @@ pm2.list(function(err, apps) {
|
|
|
36
34
|
});
|
|
37
35
|
|
|
38
36
|
function updateAndReloadNginx() {
|
|
39
|
-
|
|
40
37
|
pm2.list(function(err, apps) {
|
|
41
38
|
bailOnErr(err);
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
bailOnErr(err);
|
|
46
|
-
|
|
47
|
-
const port = 2567;
|
|
48
|
-
const addresses = [];
|
|
40
|
+
const port = 2567;
|
|
41
|
+
const addresses = [];
|
|
49
42
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
apps.forEach(function(app) {
|
|
44
|
+
addresses.push(`127.0.0.1:${ port + app.pm2_env.NODE_APP_INSTANCE }`);
|
|
45
|
+
});
|
|
53
46
|
|
|
54
|
-
|
|
47
|
+
fs.writeFileSync(NGINX_SERVERS_CONFIG_FILE, addresses.map(address => `server ${address};`).join("\n"), bailOnErr);
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
// "pm2 save"
|
|
50
|
+
pm2.dump(function(err, ret) {
|
|
51
|
+
bailOnErr(err);
|
|
59
52
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
53
|
+
// exit with success!
|
|
54
|
+
process.exit();
|
|
63
55
|
});
|
|
64
56
|
});
|
|
65
57
|
|
|
@@ -85,37 +77,3 @@ function bailOnErr(err) {
|
|
|
85
77
|
}
|
|
86
78
|
}
|
|
87
79
|
|
|
88
|
-
|
|
89
|
-
function updateNOFileConfig(cb) {
|
|
90
|
-
// const numCPU = os.cpus().length;
|
|
91
|
-
const totalmemMB = os.totalmem() / 1024 / 1024;
|
|
92
|
-
const estimatedCCUPerGB = 4000;
|
|
93
|
-
|
|
94
|
-
const maxCCU = (totalmemMB / 1024) * estimatedCCUPerGB;
|
|
95
|
-
const systemMaxNOFileLimit = maxCCU * 4;
|
|
96
|
-
const nginxMaxNOFileLimit = maxCCU * 3; // 3x because of nginx -> proxy_pass -> node:port
|
|
97
|
-
|
|
98
|
-
// immediatelly apply new nofile limit
|
|
99
|
-
exec(`ulimit -n ${systemMaxNOFileLimit}`, bailOnErr);
|
|
100
|
-
|
|
101
|
-
// update "/etc/security/limits.conf" file.
|
|
102
|
-
fs.writeFileSync("/etc/security/limits.conf", `
|
|
103
|
-
* - nofile $NOFILE_LIMIT
|
|
104
|
-
`, bailOnErr);
|
|
105
|
-
|
|
106
|
-
if (fs.existsSync(NGINX_LIMITS_CONFIG_FILE)) {
|
|
107
|
-
fs.writeFileSync(NGINX_LIMITS_CONFIG_FILE, `
|
|
108
|
-
worker_rlimit_nofile ${nginxMaxNOFileLimit};
|
|
109
|
-
|
|
110
|
-
events {
|
|
111
|
-
worker_connections ${maxCCU};
|
|
112
|
-
# multi_accept on;
|
|
113
|
-
}
|
|
114
|
-
`, cb);
|
|
115
|
-
console.log("new nofile limit:", { maxCCU, systemMaxNOFileLimit, nginxMaxNOFileLimit });
|
|
116
|
-
|
|
117
|
-
} else {
|
|
118
|
-
console.warn(NGINX_LIMITS_CONFIG_FILE, "not found.");
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
package/system-boot.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const { exec } = require('child_process');
|
|
6
|
+
|
|
7
|
+
const NGINX_LIMITS_CONFIG_FILE = '/etc/nginx/colyseus_limits.conf';
|
|
8
|
+
const LIMITS_CONF_FILE = "/etc/security/limits.conf";
|
|
9
|
+
|
|
10
|
+
// update file descriptor limits systemwide + nginx worker connections
|
|
11
|
+
|
|
12
|
+
function bailOnErr(err) {
|
|
13
|
+
if (err) {
|
|
14
|
+
console.error(err);
|
|
15
|
+
|
|
16
|
+
// exit with error!
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function updateNOFileConfig(cb) {
|
|
22
|
+
// const numCPU = os.cpus().length;
|
|
23
|
+
const totalmemMB = os.totalmem() / 1024 / 1024;
|
|
24
|
+
const estimatedCCUPerGB = 4000;
|
|
25
|
+
|
|
26
|
+
const maxCCU = (totalmemMB / 1024) * estimatedCCUPerGB;
|
|
27
|
+
const systemMaxNOFileLimit = maxCCU * 4;
|
|
28
|
+
const nginxMaxNOFileLimit = maxCCU * 3; // 3x because of nginx -> proxy_pass -> node:port
|
|
29
|
+
|
|
30
|
+
// immediatelly apply new nofile limit
|
|
31
|
+
exec(`ulimit -n ${systemMaxNOFileLimit}`, bailOnErr);
|
|
32
|
+
|
|
33
|
+
// update "/etc/security/limits.conf" file.
|
|
34
|
+
fs.writeFileSync(LIMITS_CONF_FILE, `
|
|
35
|
+
* - nofile $NOFILE_LIMIT
|
|
36
|
+
`, bailOnErr);
|
|
37
|
+
|
|
38
|
+
if (fs.existsSync(NGINX_LIMITS_CONFIG_FILE)) {
|
|
39
|
+
fs.writeFileSync(NGINX_LIMITS_CONFIG_FILE, `
|
|
40
|
+
worker_rlimit_nofile ${nginxMaxNOFileLimit};
|
|
41
|
+
|
|
42
|
+
events {
|
|
43
|
+
worker_connections ${maxCCU};
|
|
44
|
+
# multi_accept on;
|
|
45
|
+
}
|
|
46
|
+
`, cb);
|
|
47
|
+
console.log("new nofile limit:", { maxCCU, systemMaxNOFileLimit, nginxMaxNOFileLimit });
|
|
48
|
+
|
|
49
|
+
} else {
|
|
50
|
+
console.warn(NGINX_LIMITS_CONFIG_FILE, "not found.");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
updateNOFileConfig(bailOnErr);
|