@colyseus/tools 0.15.33 → 0.15.34

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/post-deploy.js +34 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/tools",
3
- "version": "0.15.33",
3
+ "version": "0.15.34",
4
4
  "description": "Colyseus Tools for Production",
5
5
  "input": "./src/index.ts",
6
6
  "main": "./build/index.js",
package/post-deploy.js CHANGED
@@ -32,20 +32,42 @@ pm2.list(function(err, apps) {
32
32
  pm2.start(CONFIG_FILE, {...opts}, onAppRunning);
33
33
 
34
34
  } else {
35
- // reload existing apps
36
- pm2.reload(CONFIG_FILE, {...opts}, function(err, apps) {
37
- bailOnErr(err);
38
-
39
- const name = apps[0].name;
40
35
 
41
- // scale app to use all CPUs available
42
- if (apps.length !== maxCPU) {
43
- pm2.scale(name, maxCPU, onAppRunning);
36
+ //
37
+ // detect if cwd has changed, and restart PM2 if it has
38
+ //
39
+ if (apps[0].pm2_env.pm_cwd !== pm2.cwd) {
40
+
41
+ //
42
+ // remove all and start again with new cwd
43
+ //
44
+ pm2.delete('all', function(err) {
45
+ // force to remove ~/.pm2 folder to avoid conflicts
46
+ fs.rmdirSync(path.join(process.env.HOME, '.pm2'), { recursive: true });
47
+
48
+ // start again
49
+ pm2.start(CONFIG_FILE, { ...opts }, onAppRunning);
50
+ });
51
+
52
+ } else {
53
+ //
54
+ // reload existing apps
55
+ //
56
+ pm2.reload(CONFIG_FILE, {...opts}, function(err, apps) {
57
+ bailOnErr(err);
58
+
59
+ const name = apps[0].name;
60
+
61
+ // scale app to use all CPUs available
62
+ if (apps.length !== maxCPU) {
63
+ pm2.scale(name, maxCPU, onAppRunning);
64
+
65
+ } else {
66
+ onAppRunning();
67
+ }
68
+ });
69
+ }
44
70
 
45
- } else {
46
- onAppRunning();
47
- }
48
- });
49
71
  }
50
72
  });
51
73