bdy 1.22.4-dev → 1.22.6-dev

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.22.4-dev",
4
+ "version": "1.22.6-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -94,7 +94,12 @@ WantedBy=multi-user.target`;
94
94
  try {
95
95
  const json = this.loadSystemConfig();
96
96
  logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
97
- await this.stop();
97
+ try {
98
+ await this.stop();
99
+ }
100
+ catch {
101
+ // do nothing
102
+ }
98
103
  await this.saveFile(this.getServicePath(), this.getServiceConfig(json.id, json.host, json.token, json.port, user, json.debug));
99
104
  logger_1.default.info(texts_1.LOG_AGENT_STARTING_SYSTEM);
100
105
  await this.start();
@@ -107,7 +112,12 @@ WantedBy=multi-user.target`;
107
112
  async update() {
108
113
  try {
109
114
  logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
110
- await this.stop();
115
+ try {
116
+ await this.stop();
117
+ }
118
+ catch {
119
+ // do nothing
120
+ }
111
121
  logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
112
122
  await this.ensureSystemConfigDir();
113
123
  logger_1.default.info(texts_1.LOG_AGENT_DOWNLOADING_ARCHIVE);
@@ -49,7 +49,27 @@ class AgentManagerClass {
49
49
  this.system = new system_1.default();
50
50
  }
51
51
  }
52
- start(id, host, token, port) {
52
+ start(id, host, token, port, onProcessExit = () => { }) {
53
+ const onExit = () => {
54
+ logger_1.default.info('exit manager');
55
+ onProcessExit();
56
+ if (this.ws) {
57
+ logger_1.default.info('close websocket');
58
+ this.ws.clients.forEach((client) => client.terminate());
59
+ this.ws.close();
60
+ }
61
+ if (this.server) {
62
+ logger_1.default.info('close server');
63
+ this.server.closeAllConnections();
64
+ this.server.close(() => {
65
+ process.exit(0);
66
+ });
67
+ }
68
+ setTimeout(() => process.exit(0), 1000);
69
+ };
70
+ process.on('SIGINT', onExit);
71
+ process.on('SIGTERM', onExit);
72
+ process.on('SIGQUIT', onExit);
53
73
  this.load(id, host, token, port).then();
54
74
  }
55
75
  async tryFetch() {
@@ -256,7 +276,7 @@ class AgentManagerClass {
256
276
  enabled: !this.agent?.disabled,
257
277
  target: !!this.agent?.target,
258
278
  tunneling: !!this.agent?.tunneling,
259
- proxy: !!this.agent?.proxy
279
+ proxy: !!this.agent?.proxy,
260
280
  });
261
281
  }
262
282
  processBody(req) {
@@ -532,6 +552,7 @@ class AgentManagerClass {
532
552
  this.ws.on('connection', (con, id) => this.processWebsocketConnection(con, id));
533
553
  this.server.on('upgrade', (req, socket, head) => this.processUpgrade(req, socket, head));
534
554
  this.server.on('error', async (err) => {
555
+ logger_1.default.info(err);
535
556
  if (err.code === 'EADDRINUSE') {
536
557
  await this.disableAgentAndExit(texts_1.LOG_ERROR_STARTING_AGENT_SERVER);
537
558
  }
@@ -111,7 +111,12 @@ class AgentOsx extends system_1.default {
111
111
  try {
112
112
  const json = this.loadSystemConfig();
113
113
  logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
114
- await this.stop();
114
+ try {
115
+ await this.stop();
116
+ }
117
+ catch {
118
+ // do nothing
119
+ }
115
120
  await this.saveFile(this.getServicePath(), this.getServiceConfig(json.id, json.host, json.token, json.port, user, json.debug));
116
121
  logger_1.default.info(texts_1.LOG_AGENT_STARTING_SYSTEM);
117
122
  await this.start();
@@ -124,7 +129,12 @@ class AgentOsx extends system_1.default {
124
129
  async update() {
125
130
  try {
126
131
  logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
127
- await this.stop();
132
+ try {
133
+ await this.stop();
134
+ }
135
+ catch {
136
+ // do nothing
137
+ }
128
138
  logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
129
139
  await this.ensureSystemConfigDir();
130
140
  logger_1.default.info(texts_1.LOG_AGENT_DOWNLOADING_ARCHIVE);
@@ -262,16 +262,11 @@ class AgentSystem {
262
262
  logger_1.default.changeRootPath(this.getNewAgentConfigDir());
263
263
  logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_STARTED);
264
264
  output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_STARTED);
265
- const onProcessExit = () => {
265
+ manager_1.default.start(json.id, json.host, json.token, json.port, () => {
266
266
  logger_1.default.info(texts_1.TXT_AGENT_STANDALONE_EXITING);
267
267
  output_1.default.normal(texts_1.TXT_AGENT_STANDALONE_EXITING);
268
268
  this.clearStandaloneProcConfig();
269
- process.exit(0);
270
- };
271
- process.on('SIGINT', onProcessExit);
272
- process.on('SIGTERM', onProcessExit);
273
- process.on('SIGQUIT', onProcessExit);
274
- manager_1.default.start(json.id, json.host, json.token, json.port);
269
+ });
275
270
  }
276
271
  clearStandaloneProcConfig() {
277
272
  try {
@@ -64,7 +64,12 @@ class AgentWindows extends system_1.default {
64
64
  async update() {
65
65
  try {
66
66
  logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
67
- await this.stop();
67
+ try {
68
+ await this.stop();
69
+ }
70
+ catch {
71
+ // do nothing
72
+ }
68
73
  logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
69
74
  await this.ensureSystemConfigDir();
70
75
  logger_1.default.info(texts_1.LOG_AGENT_DOWNLOADING_ARCHIVE);
@@ -87,7 +92,12 @@ class AgentWindows extends system_1.default {
87
92
  async changeUser(user, pass) {
88
93
  try {
89
94
  logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
90
- await this.stop();
95
+ try {
96
+ await this.stop();
97
+ }
98
+ catch {
99
+ // do nothing
100
+ }
91
101
  if (user && pass) {
92
102
  await this.nssm(`set bdy ObjectName ${user} ${pass}`);
93
103
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.22.4-dev",
4
+ "version": "1.22.6-dev",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {