@colyseus/tools 0.15.30 → 0.15.32
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 -3
- package/post-deploy.js +52 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colyseus/tools",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.32",
|
|
4
4
|
"description": "Colyseus Tools for Production",
|
|
5
5
|
"input": "./src/index.ts",
|
|
6
6
|
"main": "./build/index.js",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"cors": "^2.8.5",
|
|
42
42
|
"dotenv": "^8.2.0",
|
|
43
43
|
"express": "^4.16.2",
|
|
44
|
-
"@colyseus/
|
|
45
|
-
"@colyseus/
|
|
44
|
+
"@colyseus/core": "^0.15.23",
|
|
45
|
+
"@colyseus/ws-transport": "^0.15.1"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
package/post-deploy.js
CHANGED
|
@@ -7,8 +7,6 @@ const path = require('path');
|
|
|
7
7
|
const opts = { env: process.env.NODE_ENV || "production" };
|
|
8
8
|
const maxCPU = os.cpus().length;
|
|
9
9
|
|
|
10
|
-
const NGINX_SERVERS_CONFIG_FILE = '/etc/nginx/colyseus_servers.conf';
|
|
11
|
-
|
|
12
10
|
// allow deploying from other path as root.
|
|
13
11
|
if (process.env.npm_config_local_prefix) {
|
|
14
12
|
process.chdir(process.env.npm_config_local_prefix);
|
|
@@ -31,7 +29,7 @@ pm2.list(function(err, apps) {
|
|
|
31
29
|
|
|
32
30
|
if (apps.length === 0) {
|
|
33
31
|
// first deploy
|
|
34
|
-
pm2.start(CONFIG_FILE, {...opts},
|
|
32
|
+
pm2.start(CONFIG_FILE, {...opts}, onAppRunning);
|
|
35
33
|
|
|
36
34
|
} else {
|
|
37
35
|
// reload existing apps
|
|
@@ -42,17 +40,63 @@ pm2.list(function(err, apps) {
|
|
|
42
40
|
|
|
43
41
|
// scale app to use all CPUs available
|
|
44
42
|
if (apps.length !== maxCPU) {
|
|
45
|
-
pm2.scale(name, maxCPU,
|
|
43
|
+
pm2.scale(name, maxCPU, onAppRunning);
|
|
46
44
|
|
|
47
45
|
} else {
|
|
48
|
-
|
|
46
|
+
onAppRunning();
|
|
49
47
|
}
|
|
50
48
|
});
|
|
51
49
|
}
|
|
52
50
|
});
|
|
53
51
|
|
|
52
|
+
function onAppRunning() {
|
|
53
|
+
updateColyseusBootService();
|
|
54
|
+
updateAndReloadNginx();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function updateColyseusBootService() {
|
|
58
|
+
//
|
|
59
|
+
// Update colyseus-boot.service to use the correct paths for the application
|
|
60
|
+
//
|
|
61
|
+
|
|
62
|
+
const COLYSEUS_CLOUD_BOOT_SERVICE = '/etc/systemd/system/colyseus-boot.service';
|
|
63
|
+
|
|
64
|
+
// ignore if no boot service found
|
|
65
|
+
if (!fs.existsSync(COLYSEUS_CLOUD_BOOT_SERVICE)) { return; }
|
|
66
|
+
|
|
67
|
+
const workingDirectory = pm2.cwd;
|
|
68
|
+
const execStart = __filename;
|
|
69
|
+
|
|
70
|
+
const contents = fs.readFileSync(COLYSEUS_CLOUD_BOOT_SERVICE, 'utf8');
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
fs.writeFileSync(COLYSEUS_CLOUD_BOOT_SERVICE, contents
|
|
74
|
+
.replace(/WorkingDirectory=(.*)/, `WorkingDirectory=${workingDirectory}`)
|
|
75
|
+
.replace(/ExecStart=(.*)/, `ExecStart=${execStart}`));
|
|
76
|
+
} catch (e) {
|
|
77
|
+
// couldn't write to file
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
54
81
|
function updateAndReloadNginx() {
|
|
82
|
+
//
|
|
83
|
+
// If you are self-hosting and reading this file, consider using the
|
|
84
|
+
// following in your self-hosted environment:
|
|
85
|
+
//
|
|
86
|
+
// #!/bin/bash
|
|
87
|
+
// # Requires fswatch (`apt install fswatch`)
|
|
88
|
+
// # Reload NGINX when colyseus_servers.conf changes
|
|
89
|
+
// fswatch /etc/nginx/colyseus_servers.conf -m poll_monitor --event=Updated | while read event
|
|
90
|
+
// do
|
|
91
|
+
// service nginx reload
|
|
92
|
+
// done
|
|
93
|
+
|
|
94
|
+
const NGINX_SERVERS_CONFIG_FILE = '/etc/nginx/colyseus_servers.conf';
|
|
95
|
+
|
|
55
96
|
pm2.list(function(err, apps) {
|
|
97
|
+
if (apps.length === 0) {
|
|
98
|
+
err = "no apps running.";
|
|
99
|
+
}
|
|
56
100
|
bailOnErr(err);
|
|
57
101
|
|
|
58
102
|
const port = 2567;
|
|
@@ -62,28 +106,18 @@ function updateAndReloadNginx() {
|
|
|
62
106
|
addresses.push(`unix:/run/colyseus/${ port + app.pm2_env.NODE_APP_INSTANCE }.sock`);
|
|
63
107
|
});
|
|
64
108
|
|
|
109
|
+
// write NGINX config
|
|
65
110
|
fs.writeFileSync(NGINX_SERVERS_CONFIG_FILE, addresses.map(address => `server ${address};`).join("\n"), bailOnErr);
|
|
66
111
|
|
|
67
112
|
// "pm2 save"
|
|
68
|
-
pm2.dump(function(err, ret) {
|
|
113
|
+
pm2.dump(function (err, ret) {
|
|
69
114
|
bailOnErr(err);
|
|
70
115
|
|
|
71
116
|
// exit with success!
|
|
72
117
|
process.exit();
|
|
73
118
|
});
|
|
74
|
-
});
|
|
75
119
|
|
|
76
|
-
|
|
77
|
-
// If you are self-hosting and reading this file, consider using the
|
|
78
|
-
// following in your self-hosted environment:
|
|
79
|
-
//
|
|
80
|
-
// #!/bin/bash
|
|
81
|
-
// # Requires fswatch (`apt install fswatch`)
|
|
82
|
-
// # Reload NGINX when colyseus_servers.conf changes
|
|
83
|
-
// fswatch /etc/nginx/colyseus_servers.conf -m poll_monitor --event=Updated | while read event
|
|
84
|
-
// do
|
|
85
|
-
// service nginx reload
|
|
86
|
-
// done
|
|
120
|
+
});
|
|
87
121
|
}
|
|
88
122
|
|
|
89
123
|
function bailOnErr(err) {
|