@dxos/phoenix 0.8.3-staging.0fa589b → 0.8.4-main.84f28bd
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/dist/lib/{node/index.cjs → browser/index.mjs} +61 -84
- package/dist/lib/{node/index.cjs.map → browser/index.mjs.map} +2 -2
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node-esm/index.mjs +8 -8
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/dist/lib/node/meta.json +0 -1
|
@@ -1,76 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var node_exports = {};
|
|
30
|
-
__export(node_exports, {
|
|
31
|
-
Phoenix: () => Phoenix,
|
|
32
|
-
WatchDog: () => WatchDog
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(node_exports);
|
|
35
|
-
var import_node_child_process = require("node:child_process");
|
|
36
|
-
var import_node_fs = require("node:fs");
|
|
37
|
-
var import_node_path = require("node:path");
|
|
38
|
-
var import_pkg_up = __toESM(require("pkg-up"));
|
|
39
|
-
var import_invariant = require("@dxos/invariant");
|
|
40
|
-
var import_log = require("@dxos/log");
|
|
41
|
-
var import_node_fs2 = require("node:fs");
|
|
42
|
-
var import_async = require("@dxos/async");
|
|
43
|
-
var import_node_child_process2 = require("node:child_process");
|
|
44
|
-
var import_node_fs3 = require("node:fs");
|
|
45
|
-
var import_async2 = require("@dxos/async");
|
|
46
|
-
var import_invariant2 = require("@dxos/invariant");
|
|
47
|
-
var import_log2 = require("@dxos/log");
|
|
48
|
-
const import_meta = {};
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
|
|
3
|
+
// src/phoenix.ts
|
|
4
|
+
import { fork } from "@dxos/node-std/child_process";
|
|
5
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, unlinkSync, writeFileSync } from "@dxos/node-std/fs";
|
|
6
|
+
import { dirname, join } from "@dxos/node-std/path";
|
|
7
|
+
import pkgUp from "pkg-up";
|
|
8
|
+
import { invariant } from "@dxos/invariant";
|
|
9
|
+
import { log } from "@dxos/log";
|
|
10
|
+
|
|
11
|
+
// src/utils.ts
|
|
12
|
+
import { existsSync, readFileSync } from "@dxos/node-std/fs";
|
|
13
|
+
import { waitForCondition } from "@dxos/async";
|
|
14
|
+
|
|
15
|
+
// src/defs.ts
|
|
49
16
|
var WATCHDOG_START_TIMEOUT = 1e4;
|
|
50
17
|
var WATCHDOG_STOP_TIMEOUT = 1e3;
|
|
51
18
|
var WATCHDOG_CHECK_INTERVAL = 50;
|
|
52
|
-
|
|
53
|
-
|
|
19
|
+
|
|
20
|
+
// src/utils.ts
|
|
21
|
+
var waitForPidDeletion = async (pidFile) => waitForCondition({
|
|
22
|
+
condition: () => !existsSync(pidFile),
|
|
54
23
|
timeout: WATCHDOG_STOP_TIMEOUT,
|
|
55
24
|
interval: WATCHDOG_CHECK_INTERVAL
|
|
56
25
|
});
|
|
57
|
-
var waitForPidFileBeingFilledWithInfo = async (pidFile) =>
|
|
58
|
-
condition: () =>
|
|
26
|
+
var waitForPidFileBeingFilledWithInfo = async (pidFile) => waitForCondition({
|
|
27
|
+
condition: () => readFileSync(pidFile, {
|
|
59
28
|
encoding: "utf-8"
|
|
60
29
|
}).includes("pid"),
|
|
61
30
|
timeout: WATCHDOG_START_TIMEOUT,
|
|
62
31
|
interval: WATCHDOG_CHECK_INTERVAL,
|
|
63
32
|
error: new Error("Lock file is not being propagated with info.")
|
|
64
33
|
});
|
|
65
|
-
|
|
66
|
-
|
|
34
|
+
|
|
35
|
+
// src/phoenix.ts
|
|
36
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/common/phoenix/src/phoenix.ts";
|
|
37
|
+
var scriptDir = typeof __dirname === "string" ? __dirname : dirname(new URL(import.meta.url).pathname);
|
|
67
38
|
var Phoenix = class _Phoenix {
|
|
68
39
|
/**
|
|
69
40
|
* Starts detached watchdog process which starts and monitors selected command.
|
|
70
41
|
*/
|
|
71
42
|
static async start(params) {
|
|
72
43
|
{
|
|
73
|
-
if ((
|
|
44
|
+
if (existsSync2(params.pidFile)) {
|
|
74
45
|
await _Phoenix.stop(params.pidFile);
|
|
75
46
|
}
|
|
76
47
|
await waitForPidDeletion(params.pidFile);
|
|
@@ -81,27 +52,27 @@ var Phoenix = class _Phoenix {
|
|
|
81
52
|
params.errFile,
|
|
82
53
|
params.pidFile
|
|
83
54
|
].forEach((filename) => {
|
|
84
|
-
if (!(
|
|
85
|
-
|
|
55
|
+
if (!existsSync2(filename)) {
|
|
56
|
+
mkdirSync(dirname(filename), {
|
|
86
57
|
recursive: true
|
|
87
58
|
});
|
|
88
|
-
|
|
59
|
+
writeFileSync(filename, "", {
|
|
89
60
|
encoding: "utf-8"
|
|
90
61
|
});
|
|
91
62
|
}
|
|
92
63
|
});
|
|
93
64
|
}
|
|
94
|
-
const watchdogPath =
|
|
65
|
+
const watchdogPath = join(dirname(pkgUp.sync({
|
|
95
66
|
cwd: scriptDir
|
|
96
67
|
})), "bin", "watchdog.mjs");
|
|
97
|
-
const watchDog =
|
|
68
|
+
const watchDog = fork(watchdogPath, [
|
|
98
69
|
JSON.stringify(params)
|
|
99
70
|
], {
|
|
100
71
|
detached: true
|
|
101
72
|
});
|
|
102
73
|
watchDog.on("exit", (code, signal) => {
|
|
103
74
|
if (code && code !== 0) {
|
|
104
|
-
|
|
75
|
+
log.error("Monitor died unexpectedly", {
|
|
105
76
|
code,
|
|
106
77
|
signal
|
|
107
78
|
}, {
|
|
@@ -113,7 +84,7 @@ var Phoenix = class _Phoenix {
|
|
|
113
84
|
}
|
|
114
85
|
});
|
|
115
86
|
watchDog.on("error", (err) => {
|
|
116
|
-
|
|
87
|
+
log.error("Monitor error", {
|
|
117
88
|
err
|
|
118
89
|
}, {
|
|
119
90
|
F: __dxlog_file,
|
|
@@ -131,10 +102,10 @@ var Phoenix = class _Phoenix {
|
|
|
131
102
|
* Stops detached watchdog process by PID info written down in PID file.
|
|
132
103
|
*/
|
|
133
104
|
static async stop(pidFile, force = false) {
|
|
134
|
-
if (!(
|
|
105
|
+
if (!existsSync2(pidFile)) {
|
|
135
106
|
throw new Error("PID file does not exist");
|
|
136
107
|
}
|
|
137
|
-
const fileContent = (
|
|
108
|
+
const fileContent = readFileSync2(pidFile, {
|
|
138
109
|
encoding: "utf-8"
|
|
139
110
|
});
|
|
140
111
|
if (!fileContent.includes("pid")) {
|
|
@@ -145,7 +116,7 @@ var Phoenix = class _Phoenix {
|
|
|
145
116
|
try {
|
|
146
117
|
process.kill(pid, signal);
|
|
147
118
|
} catch (err) {
|
|
148
|
-
|
|
119
|
+
invariant(err instanceof Error, "Invalid error type", {
|
|
149
120
|
F: __dxlog_file,
|
|
150
121
|
L: 86,
|
|
151
122
|
S: this,
|
|
@@ -155,25 +126,32 @@ var Phoenix = class _Phoenix {
|
|
|
155
126
|
]
|
|
156
127
|
});
|
|
157
128
|
if (err.message.includes("ESRCH") || err.name.includes("ESRCH")) {
|
|
158
|
-
|
|
129
|
+
unlinkSync(pidFile);
|
|
159
130
|
} else {
|
|
160
131
|
throw err;
|
|
161
132
|
}
|
|
162
133
|
}
|
|
163
134
|
}
|
|
164
135
|
static info(pidFile) {
|
|
165
|
-
return JSON.parse((
|
|
136
|
+
return JSON.parse(readFileSync2(pidFile, {
|
|
166
137
|
encoding: "utf-8"
|
|
167
138
|
}));
|
|
168
139
|
}
|
|
169
140
|
};
|
|
141
|
+
|
|
142
|
+
// src/watchdog.ts
|
|
143
|
+
import { spawn } from "@dxos/node-std/child_process";
|
|
144
|
+
import { existsSync as existsSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "@dxos/node-std/fs";
|
|
145
|
+
import { synchronized } from "@dxos/async";
|
|
146
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
147
|
+
import { log as log2 } from "@dxos/log";
|
|
170
148
|
function _ts_decorate(decorators, target, key, desc) {
|
|
171
149
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
172
150
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
173
151
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
174
152
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
175
153
|
}
|
|
176
|
-
var __dxlog_file2 = "/
|
|
154
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/phoenix/src/watchdog.ts";
|
|
177
155
|
var WatchDog = class {
|
|
178
156
|
constructor(_params) {
|
|
179
157
|
this._params = _params;
|
|
@@ -185,7 +163,7 @@ var WatchDog = class {
|
|
|
185
163
|
...this._params
|
|
186
164
|
};
|
|
187
165
|
this._log(`Spawning process \`\`\`${command} ${args?.join(" ")}\`\`\``);
|
|
188
|
-
this._child =
|
|
166
|
+
this._child = spawn(command, args, {
|
|
189
167
|
cwd,
|
|
190
168
|
shell,
|
|
191
169
|
env,
|
|
@@ -203,8 +181,8 @@ var WatchDog = class {
|
|
|
203
181
|
await this.restart();
|
|
204
182
|
}
|
|
205
183
|
this._log(`Stopped with exit code ${code} (signal: ${signal}).`);
|
|
206
|
-
if ((
|
|
207
|
-
(
|
|
184
|
+
if (existsSync3(this._params.pidFile)) {
|
|
185
|
+
unlinkSync2(this._params.pidFile);
|
|
208
186
|
}
|
|
209
187
|
});
|
|
210
188
|
const childInfo = {
|
|
@@ -213,7 +191,7 @@ var WatchDog = class {
|
|
|
213
191
|
restarts: this._restarts,
|
|
214
192
|
...this._params
|
|
215
193
|
};
|
|
216
|
-
(
|
|
194
|
+
writeFileSync2(this._params.pidFile, JSON.stringify(childInfo, void 0, 2), {
|
|
217
195
|
encoding: "utf-8"
|
|
218
196
|
});
|
|
219
197
|
await waitForPidFileBeingFilledWithInfo(this._params.pidFile);
|
|
@@ -226,8 +204,8 @@ var WatchDog = class {
|
|
|
226
204
|
return;
|
|
227
205
|
}
|
|
228
206
|
await this._killWithSignal("SIGKILL");
|
|
229
|
-
if ((
|
|
230
|
-
(
|
|
207
|
+
if (existsSync3(this._params.pidFile)) {
|
|
208
|
+
unlinkSync2(this._params.pidFile);
|
|
231
209
|
}
|
|
232
210
|
await waitForPidDeletion(this._params.pidFile);
|
|
233
211
|
}
|
|
@@ -236,7 +214,7 @@ var WatchDog = class {
|
|
|
236
214
|
if (this._params.maxRestarts !== void 0 && this._restarts >= this._params.maxRestarts) {
|
|
237
215
|
this._err("Max restarts number is reached");
|
|
238
216
|
} else {
|
|
239
|
-
(
|
|
217
|
+
log2("Restarting...", void 0, {
|
|
240
218
|
F: __dxlog_file2,
|
|
241
219
|
L: 120,
|
|
242
220
|
S: this,
|
|
@@ -247,7 +225,7 @@ var WatchDog = class {
|
|
|
247
225
|
}
|
|
248
226
|
}
|
|
249
227
|
async _killWithSignal(signal) {
|
|
250
|
-
(
|
|
228
|
+
invariant2(this._child?.pid, "Child process has no pid.", {
|
|
251
229
|
F: __dxlog_file2,
|
|
252
230
|
L: 127,
|
|
253
231
|
S: this,
|
|
@@ -260,28 +238,27 @@ var WatchDog = class {
|
|
|
260
238
|
this._child = void 0;
|
|
261
239
|
}
|
|
262
240
|
_log(message) {
|
|
263
|
-
(
|
|
241
|
+
writeFileSync2(this._params.logFile, message + "\n", {
|
|
264
242
|
flag: "a+",
|
|
265
243
|
encoding: "utf-8"
|
|
266
244
|
});
|
|
267
245
|
}
|
|
268
246
|
_err(message) {
|
|
269
247
|
this._log(message);
|
|
270
|
-
(
|
|
248
|
+
writeFileSync2(this._params.errFile, message + "\n", {
|
|
271
249
|
flag: "a+",
|
|
272
250
|
encoding: "utf-8"
|
|
273
251
|
});
|
|
274
252
|
}
|
|
275
253
|
};
|
|
276
254
|
_ts_decorate([
|
|
277
|
-
|
|
255
|
+
synchronized
|
|
278
256
|
], WatchDog.prototype, "start", null);
|
|
279
257
|
_ts_decorate([
|
|
280
|
-
|
|
258
|
+
synchronized
|
|
281
259
|
], WatchDog.prototype, "kill", null);
|
|
282
|
-
|
|
283
|
-
0 && (module.exports = {
|
|
260
|
+
export {
|
|
284
261
|
Phoenix,
|
|
285
262
|
WatchDog
|
|
286
|
-
}
|
|
287
|
-
//# sourceMappingURL=index.
|
|
263
|
+
};
|
|
264
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/phoenix.ts", "../../../src/utils.ts", "../../../src/defs.ts", "../../../src/watchdog.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { fork } from 'node:child_process';\nimport { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport pkgUp from 'pkg-up';\n\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { waitForPidDeletion, waitForPidFileBeingFilledWithInfo } from './utils';\nimport { type ProcessInfo, type WatchDogParams } from './watchdog';\n\nconst scriptDir = typeof __dirname === 'string' ? __dirname : dirname(new URL(import.meta.url).pathname);\n\n/**\n * Utils to start/stop detached process with errors and logs handling.\n */\nexport class Phoenix {\n /**\n * Starts detached watchdog process which starts and monitors selected command.\n */\n static async start(params: WatchDogParams): Promise<ProcessInfo> {\n {\n // Clear stale pid file.\n if (existsSync(params.pidFile)) {\n await Phoenix.stop(params.pidFile);\n }\n\n await waitForPidDeletion(params.pidFile);\n }\n\n {\n // Create log folders.\n [params.logFile, params.errFile, params.pidFile].forEach((filename) => {\n if (!existsSync(filename)) {\n mkdirSync(dirname(filename), { recursive: true });\n writeFileSync(filename, '', { encoding: 'utf-8' });\n }\n });\n }\n\n const watchdogPath = join(dirname(pkgUp.sync({ cwd: scriptDir })!), 'bin', 'watchdog.mjs');\n\n const watchDog = fork(watchdogPath, [JSON.stringify(params)], {\n detached: true,\n });\n\n watchDog.on('exit', (code, signal) => {\n if (code && code !== 0) {\n log.error('Monitor died unexpectedly', { code, signal });\n }\n });\n\n watchDog.on('error', (err) => {\n log.error('Monitor error', { err });\n });\n\n await waitForPidFileBeingFilledWithInfo(params.pidFile);\n\n watchDog.disconnect();\n watchDog.unref();\n\n return Phoenix.info(params.pidFile);\n }\n\n /**\n * Stops detached watchdog process by PID info written down in PID file.\n */\n static async stop(pidFile: string, force = false): Promise<void> {\n if (!existsSync(pidFile)) {\n throw new Error('PID file does not exist');\n }\n const fileContent = readFileSync(pidFile, { encoding: 'utf-8' });\n if (!fileContent.includes('pid')) {\n throw new Error('Invalid PID file content');\n }\n\n const { pid } = JSON.parse(fileContent);\n const signal: NodeJS.Signals = force ? 'SIGKILL' : 'SIGINT';\n try {\n process.kill(pid, signal);\n } catch (err) {\n invariant(err instanceof Error, 'Invalid error type');\n if (err.message.includes('ESRCH') || err.name.includes('ESRCH')) {\n // Process is already dead.\n unlinkSync(pidFile);\n } else {\n throw err;\n }\n }\n }\n\n static info(pidFile: string): ProcessInfo {\n return JSON.parse(readFileSync(pidFile, { encoding: 'utf-8' }));\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { existsSync, readFileSync } from 'node:fs';\n\nimport { waitForCondition } from '@dxos/async';\n\nimport { WATCHDOG_CHECK_INTERVAL, WATCHDOG_START_TIMEOUT, WATCHDOG_STOP_TIMEOUT } from './defs';\n\nexport const waitForPidCreation = async (pidFile: string) =>\n waitForCondition({\n condition: () => existsSync(pidFile),\n timeout: WATCHDOG_START_TIMEOUT,\n interval: WATCHDOG_CHECK_INTERVAL,\n });\n\nexport const waitForPidDeletion = async (pidFile: string) =>\n waitForCondition({\n condition: () => !existsSync(pidFile),\n timeout: WATCHDOG_STOP_TIMEOUT,\n interval: WATCHDOG_CHECK_INTERVAL,\n });\n\nexport const waitForPidFileBeingFilledWithInfo = async (pidFile: string) =>\n waitForCondition({\n condition: () => readFileSync(pidFile, { encoding: 'utf-8' }).includes('pid'),\n timeout: WATCHDOG_START_TIMEOUT,\n interval: WATCHDOG_CHECK_INTERVAL,\n error: new Error('Lock file is not being propagated with info.'),\n });\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const LOCK_TIMEOUT = 1_000;\nexport const LOCK_CHECK_INTERVAL = 50;\nexport const WATCHDOG_START_TIMEOUT = 10_000;\nexport const WATCHDOG_STOP_TIMEOUT = 1_000;\nexport const WATCHDOG_CHECK_INTERVAL = 50;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process';\nimport { existsSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { type FileHandle } from 'node:fs/promises';\n\nimport { synchronized } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { waitForPidDeletion, waitForPidFileBeingFilledWithInfo } from './utils';\n\nexport type ProcessInfo = WatchDogParams & {\n pid?: number;\n started?: number;\n restarts?: number;\n running?: boolean;\n};\n\nexport type WatchDogParams = {\n profile?: string; // Human readable process identifier\n pidFile: string; // Path to PID file\n\n //\n // Log files and associated logging options for this instance\n //\n logFile: string; // Path to log output all logs\n errFile: string; // Path to log output from child stderr\n\n //\n // Basic configuration options\n //\n maxRestarts?: number | undefined; // Sets the maximum number of times a given script should run\n killTree?: boolean | undefined; // Kills the entire child process tree on `exit`\n\n //\n // Command to spawn as well as options and other vars\n // (env, cwd, etc) to pass along\n //\n command: string; // Binary to run (default: 'node')\n args?: string[] | undefined; // Additional arguments to pass to the script,\n\n //\n // More specific options to pass along to `child_process.spawn` which\n // will override anything passed to the `spawnWith` option\n //\n env?: NodeJS.ProcessEnv | undefined;\n cwd?: string | undefined;\n shell?: boolean | undefined;\n};\n\nexport class WatchDog {\n private _lock?: FileHandle; // TODO(burdon): Not used?\n private _child?: ChildProcessWithoutNullStreams;\n private _restarts = 0;\n\n constructor(private readonly _params: WatchDogParams) {}\n\n @synchronized\n async start(): Promise<void> {\n const { cwd, shell, env, command, args } = { cwd: process.cwd(), ...this._params };\n\n this._log(`Spawning process \\`\\`\\`${command} ${args?.join(' ')}\\`\\`\\``);\n this._child = spawn(command, args, { cwd, shell, env, stdio: 'pipe' });\n\n this._child.stdout.on('data', (data: Uint8Array) => {\n this._log(String(data));\n });\n this._child.stderr.on('data', (data: Uint8Array) => {\n this._err(data);\n });\n this._child.on('close', async (code: number, signal: number | NodeJS.Signals) => {\n if (code && code !== 0 && signal !== 'SIGINT' && signal !== 'SIGKILL') {\n this._err(`Died unexpectedly with exit code ${code} (signal: ${signal}).`);\n await this.restart();\n }\n this._log(`Stopped with exit code ${code} (signal: ${signal}).`);\n if (existsSync(this._params.pidFile)) {\n unlinkSync(this._params.pidFile);\n }\n });\n\n const childInfo: ProcessInfo = {\n pid: this._child.pid,\n started: Date.now(),\n restarts: this._restarts,\n ...this._params,\n };\n\n writeFileSync(this._params.pidFile, JSON.stringify(childInfo, undefined, 2), { encoding: 'utf-8' });\n\n await waitForPidFileBeingFilledWithInfo(this._params.pidFile);\n }\n\n /**\n * Sends SIGKILL to the child process and the tree it spawned (if `killTree` param is `true`).\n */\n @synchronized\n async kill(): Promise<void> {\n if (!this._child) {\n return;\n }\n\n await this._killWithSignal('SIGKILL');\n\n if (existsSync(this._params.pidFile)) {\n unlinkSync(this._params.pidFile);\n }\n\n await waitForPidDeletion(this._params.pidFile);\n }\n\n async restart(): Promise<void> {\n await this.kill();\n if (this._params.maxRestarts !== undefined && this._restarts >= this._params.maxRestarts) {\n this._err('Max restarts number is reached');\n } else {\n log('Restarting...');\n this._restarts++;\n await this.start();\n }\n }\n\n async _killWithSignal(signal: number | NodeJS.Signals): Promise<void> {\n invariant(this._child?.pid, 'Child process has no pid.');\n this._child.kill(signal);\n this._child = undefined;\n }\n\n private _log(message: string | Uint8Array): void {\n writeFileSync(this._params.logFile, message + '\\n', {\n flag: 'a+',\n encoding: 'utf-8',\n });\n }\n\n private _err(message: string | Uint8Array): void {\n this._log(message);\n writeFileSync(this._params.errFile, message + '\\n', {\n flag: 'a+',\n encoding: 'utf-8',\n });\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,YAAY;AACrB,SAASC,cAAAA,aAAYC,WAAWC,gBAAAA,eAAcC,YAAYC,qBAAqB;AAC/E,SAASC,SAASC,YAAY;AAC9B,OAAOC,WAAW;AAElB,SAASC,iBAAiB;AAC1B,SAASC,WAAW;;;ACNpB,SAASC,YAAYC,oBAAoB;AAEzC,SAASC,wBAAwB;;;ACA1B,IAAMC,yBAAyB;AAC/B,IAAMC,wBAAwB;AAC9B,IAAMC,0BAA0B;;;ADShC,IAAMC,qBAAqB,OAAOC,YACvCC,iBAAiB;EACfC,WAAW,MAAM,CAACC,WAAWH,OAAAA;EAC7BI,SAASC;EACT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,KAAKzB,QAAQwB,OAAO;IACjC;AAEA,UAAMgB,mBAAmB,KAAKxC,QAAQwB,OAAO;EAC/C;EAEA,MAAMF,UAAyB;AAC7B,UAAM,KAAKgB,KAAI;AACf,QAAI,KAAKtC,QAAQyC,gBAAgBN,UAAa,KAAKlC,aAAa,KAAKD,QAAQyC,aAAa;AACxF,WAAKtB,KAAK,gCAAA;IACZ,OAAO;AACLuB,MAAAA,KAAI,iBAAA,QAAA;;;;;;AACJ,WAAKzC;AACL,YAAM,KAAKC,MAAK;IAClB;EACF;EAEA,MAAMqC,gBAAgBlB,QAAgD;AACpEsB,IAAAA,WAAU,KAAKhC,QAAQgB,KAAK,6BAAA;;;;;;;;;AAC5B,SAAKhB,OAAO2B,KAAKjB,MAAAA;AACjB,SAAKV,SAASwB;EAChB;EAEQ1B,KAAKmC,SAAoC;AAC/CZ,IAAAA,eAAc,KAAKhC,QAAQ6C,SAASD,UAAU,MAAM;MAClDE,MAAM;MACNV,UAAU;IACZ,CAAA;EACF;EAEQjB,KAAKyB,SAAoC;AAC/C,SAAKnC,KAAKmC,OAAAA;AACVZ,IAAAA,eAAc,KAAKhC,QAAQ+C,SAASH,UAAU,MAAM;MAClDE,MAAM;MACNV,UAAU;IACZ,CAAA;EACF;AACF;;;;;;;",
|
|
6
|
+
"names": ["fork", "existsSync", "mkdirSync", "readFileSync", "unlinkSync", "writeFileSync", "dirname", "join", "pkgUp", "invariant", "log", "existsSync", "readFileSync", "waitForCondition", "WATCHDOG_START_TIMEOUT", "WATCHDOG_STOP_TIMEOUT", "WATCHDOG_CHECK_INTERVAL", "waitForPidDeletion", "pidFile", "waitForCondition", "condition", "existsSync", "timeout", "WATCHDOG_STOP_TIMEOUT", "interval", "WATCHDOG_CHECK_INTERVAL", "waitForPidFileBeingFilledWithInfo", "readFileSync", "encoding", "includes", "WATCHDOG_START_TIMEOUT", "error", "Error", "scriptDir", "__dirname", "dirname", "URL", "url", "pathname", "Phoenix", "start", "params", "existsSync", "pidFile", "stop", "waitForPidDeletion", "logFile", "errFile", "forEach", "filename", "mkdirSync", "recursive", "writeFileSync", "encoding", "watchdogPath", "join", "pkgUp", "sync", "cwd", "watchDog", "fork", "JSON", "stringify", "detached", "on", "code", "signal", "log", "error", "err", "waitForPidFileBeingFilledWithInfo", "disconnect", "unref", "info", "force", "Error", "fileContent", "readFileSync", "includes", "pid", "parse", "process", "kill", "invariant", "message", "name", "unlinkSync", "spawn", "existsSync", "unlinkSync", "writeFileSync", "synchronized", "invariant", "log", "WatchDog", "_params", "_restarts", "start", "cwd", "shell", "env", "command", "args", "process", "_log", "join", "_child", "spawn", "stdio", "stdout", "on", "data", "String", "stderr", "_err", "code", "signal", "restart", "existsSync", "pidFile", "unlinkSync", "childInfo", "pid", "started", "Date", "now", "restarts", "writeFileSync", "JSON", "stringify", "undefined", "encoding", "waitForPidFileBeingFilledWithInfo", "kill", "_killWithSignal", "waitForPidDeletion", "maxRestarts", "log", "invariant", "message", "logFile", "flag", "errFile"]
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/defs.ts":{"bytes":1188,"imports":[],"format":"esm"},"src/utils.ts":{"bytes":3660,"imports":[{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"}],"format":"esm"},"src/phoenix.ts":{"bytes":11379,"imports":[{"path":"@dxos/node-std/child_process","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/watchdog.ts":{"bytes":14435,"imports":[{"path":"@dxos/node-std/child_process","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/index.ts":{"bytes":974,"imports":[{"path":"src/phoenix.ts","kind":"import-statement","original":"./phoenix"},{"path":"src/watchdog.ts","kind":"import-statement","original":"./watchdog"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":14873},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/node-std/child_process","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/node-std/path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/node-std/child_process","kind":"import-statement","external":true},{"path":"@dxos/node-std/fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["Phoenix","WatchDog"],"entryPoint":"src/index.ts","inputs":{"src/phoenix.ts":{"bytesInOutput":3081},"src/utils.ts":{"bytesInOutput":596},"src/defs.ts":{"bytesInOutput":101},"src/index.ts":{"bytesInOutput":0},"src/watchdog.ts":{"bytesInOutput":3739}},"bytes":7727}}}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// src/phoenix.ts
|
|
4
4
|
import { fork } from "node:child_process";
|
|
5
5
|
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, unlinkSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
@@ -8,16 +8,16 @@ import pkgUp from "pkg-up";
|
|
|
8
8
|
import { invariant } from "@dxos/invariant";
|
|
9
9
|
import { log } from "@dxos/log";
|
|
10
10
|
|
|
11
|
-
//
|
|
11
|
+
// src/utils.ts
|
|
12
12
|
import { existsSync, readFileSync } from "node:fs";
|
|
13
13
|
import { waitForCondition } from "@dxos/async";
|
|
14
14
|
|
|
15
|
-
//
|
|
15
|
+
// src/defs.ts
|
|
16
16
|
var WATCHDOG_START_TIMEOUT = 1e4;
|
|
17
17
|
var WATCHDOG_STOP_TIMEOUT = 1e3;
|
|
18
18
|
var WATCHDOG_CHECK_INTERVAL = 50;
|
|
19
19
|
|
|
20
|
-
//
|
|
20
|
+
// src/utils.ts
|
|
21
21
|
var waitForPidDeletion = async (pidFile) => waitForCondition({
|
|
22
22
|
condition: () => !existsSync(pidFile),
|
|
23
23
|
timeout: WATCHDOG_STOP_TIMEOUT,
|
|
@@ -32,8 +32,8 @@ var waitForPidFileBeingFilledWithInfo = async (pidFile) => waitForCondition({
|
|
|
32
32
|
error: new Error("Lock file is not being propagated with info.")
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
var __dxlog_file = "/
|
|
35
|
+
// src/phoenix.ts
|
|
36
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/common/phoenix/src/phoenix.ts";
|
|
37
37
|
var scriptDir = typeof __dirname === "string" ? __dirname : dirname(new URL(import.meta.url).pathname);
|
|
38
38
|
var Phoenix = class _Phoenix {
|
|
39
39
|
/**
|
|
@@ -139,7 +139,7 @@ var Phoenix = class _Phoenix {
|
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
141
|
|
|
142
|
-
//
|
|
142
|
+
// src/watchdog.ts
|
|
143
143
|
import { spawn } from "node:child_process";
|
|
144
144
|
import { existsSync as existsSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
145
145
|
import { synchronized } from "@dxos/async";
|
|
@@ -151,7 +151,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
151
151
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
152
152
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
153
153
|
}
|
|
154
|
-
var __dxlog_file2 = "/
|
|
154
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/phoenix/src/watchdog.ts";
|
|
155
155
|
var WatchDog = class {
|
|
156
156
|
constructor(_params) {
|
|
157
157
|
this._params = _params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"
|
|
1
|
+
{"inputs":{"src/defs.ts":{"bytes":1188,"imports":[],"format":"esm"},"src/utils.ts":{"bytes":3660,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"}],"format":"esm"},"src/phoenix.ts":{"bytes":11379,"imports":[{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/watchdog.ts":{"bytes":14435,"imports":[{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/index.ts":{"bytes":974,"imports":[{"path":"src/phoenix.ts","kind":"import-statement","original":"./phoenix"},{"path":"src/watchdog.ts","kind":"import-statement","original":"./watchdog"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":14873},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["Phoenix","WatchDog"],"entryPoint":"src/index.ts","inputs":{"src/phoenix.ts":{"bytesInOutput":3051},"src/utils.ts":{"bytesInOutput":586},"src/defs.ts":{"bytesInOutput":101},"src/index.ts":{"bytesInOutput":0},"src/watchdog.ts":{"bytesInOutput":3719}},"bytes":7726}}}
|