@bakers-build/core 0.14.1-next.1 → 0.14.1-next.3
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/src/core/proc.d.ts +10 -7
- package/dist/src/core/proc.js +50 -14
- package/package.json +2 -2
package/dist/src/core/proc.d.ts
CHANGED
|
@@ -65,16 +65,18 @@ export type VerifyOutcome = {
|
|
|
65
65
|
*/
|
|
66
66
|
export declare function verifyConductorProcess(input: VerifyProcessInput): VerifyOutcome;
|
|
67
67
|
export declare function signalVerifiedProcess(input: SignalVerifiedInput): SignalOutcome;
|
|
68
|
+
/** Runs a command and returns its stdout; throws on a non-zero exit. */
|
|
69
|
+
export type RunCommand = (file: string, args: string[]) => string;
|
|
68
70
|
/**
|
|
69
71
|
* The real probe: `/proc/<pid>/cmdline` and the owning uid of `/proc/<pid>`
|
|
70
|
-
*
|
|
72
|
+
* on Linux; one `ps -ww -o uid= -o command= -p <pid>` line on macOS (`-ww`
|
|
73
|
+
* keeps the command untruncated, so the markers are always in it).
|
|
71
74
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* guessing. Start is unaffected everywhere.
|
|
75
|
+
* Any other platform reports `supported: false`: a wrong answer here signals
|
|
76
|
+
* the wrong process, so stop degrades with a message rather than guessing.
|
|
77
|
+
* Start is unaffected everywhere.
|
|
76
78
|
*/
|
|
77
|
-
export declare function defaultProcProbe(): ProcProbe;
|
|
79
|
+
export declare function defaultProcProbe(platform?: NodeJS.Platform, run?: RunCommand): ProcProbe;
|
|
78
80
|
/** What `killRunProcesses` needs from the platform, injected for tests. */
|
|
79
81
|
export interface RunProcessProbe {
|
|
80
82
|
readonly supported: boolean;
|
|
@@ -85,7 +87,8 @@ export interface RunProcessProbe {
|
|
|
85
87
|
uidOf(pid: number): number | undefined;
|
|
86
88
|
send(pid: number, signal: NodeJS.Signals): void;
|
|
87
89
|
}
|
|
88
|
-
|
|
90
|
+
/** Linux only: it lists and reads `/proc`. */
|
|
91
|
+
export declare function defaultRunProcessProbe(platform?: NodeJS.Platform): RunProcessProbe;
|
|
89
92
|
/**
|
|
90
93
|
* Ends every process of this OS user that carries `BAKERS_RUN_UUID=<runUuid>`:
|
|
91
94
|
* the run's agent, its sandbox and background commands that outlive the
|
package/dist/src/core/proc.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
3
|
/**
|
|
3
4
|
* Substrings a live bakers-conductor foreground process's command line must all
|
|
@@ -113,17 +114,52 @@ export function signalVerifiedProcess(input) {
|
|
|
113
114
|
}
|
|
114
115
|
return { ok: true, pid: identified.pid, signal: input.signal };
|
|
115
116
|
}
|
|
117
|
+
const runCommand = (file, args) => execFileSync(file, args, {
|
|
118
|
+
encoding: 'utf8',
|
|
119
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
120
|
+
});
|
|
116
121
|
/**
|
|
117
122
|
* The real probe: `/proc/<pid>/cmdline` and the owning uid of `/proc/<pid>`
|
|
118
|
-
*
|
|
123
|
+
* on Linux; one `ps -ww -o uid= -o command= -p <pid>` line on macOS (`-ww`
|
|
124
|
+
* keeps the command untruncated, so the markers are always in it).
|
|
119
125
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* guessing. Start is unaffected everywhere.
|
|
126
|
+
* Any other platform reports `supported: false`: a wrong answer here signals
|
|
127
|
+
* the wrong process, so stop degrades with a message rather than guessing.
|
|
128
|
+
* Start is unaffected everywhere.
|
|
124
129
|
*/
|
|
125
|
-
export function defaultProcProbe() {
|
|
126
|
-
const
|
|
130
|
+
export function defaultProcProbe(platform = process.platform, run = runCommand) {
|
|
131
|
+
const send = (pid, signal) => {
|
|
132
|
+
process.kill(pid, signal);
|
|
133
|
+
};
|
|
134
|
+
if (platform === 'darwin') {
|
|
135
|
+
const psOf = (pid) => {
|
|
136
|
+
try {
|
|
137
|
+
const match = /^\s*(\d+)\s+(\S.*)$/.exec(run('ps', [
|
|
138
|
+
'-ww',
|
|
139
|
+
'-o',
|
|
140
|
+
'uid=',
|
|
141
|
+
'-o',
|
|
142
|
+
'command=',
|
|
143
|
+
'-p',
|
|
144
|
+
String(pid),
|
|
145
|
+
]).trim());
|
|
146
|
+
return match
|
|
147
|
+
? { uid: Number(match[1]), command: match[2] }
|
|
148
|
+
: undefined;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// ps exits non-zero when the pid is gone.
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
supported: true,
|
|
157
|
+
cmdlineOf: (pid) => psOf(pid)?.command,
|
|
158
|
+
uidOf: (pid) => psOf(pid)?.uid,
|
|
159
|
+
send,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const supported = platform === 'linux';
|
|
127
163
|
return {
|
|
128
164
|
supported,
|
|
129
165
|
cmdlineOf(pid) {
|
|
@@ -152,17 +188,17 @@ export function defaultProcProbe() {
|
|
|
152
188
|
return undefined;
|
|
153
189
|
}
|
|
154
190
|
},
|
|
155
|
-
send
|
|
156
|
-
process.kill(pid, signal);
|
|
157
|
-
},
|
|
191
|
+
send,
|
|
158
192
|
};
|
|
159
193
|
}
|
|
160
|
-
|
|
161
|
-
|
|
194
|
+
/** Linux only: it lists and reads `/proc`. */
|
|
195
|
+
export function defaultRunProcessProbe(platform = process.platform) {
|
|
196
|
+
const base = defaultProcProbe(platform);
|
|
197
|
+
const supported = platform === 'linux';
|
|
162
198
|
return {
|
|
163
|
-
supported
|
|
199
|
+
supported,
|
|
164
200
|
pids() {
|
|
165
|
-
if (!
|
|
201
|
+
if (!supported)
|
|
166
202
|
return [];
|
|
167
203
|
return readdirSync('/proc')
|
|
168
204
|
.filter((name) => /^\d+$/.test(name))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bakers-build/core",
|
|
3
|
-
"version": "0.14.1-next.
|
|
3
|
+
"version": "0.14.1-next.3",
|
|
4
4
|
"description": "bakers.build surface-agnostic kernel: host contract, split-config helpers, addon preset/discovery machinery, shared primitives.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"yaml": "^2.7.0"
|
|
41
41
|
},
|
|
42
42
|
"bakersBuild": {
|
|
43
|
-
"commit": "
|
|
43
|
+
"commit": "e28f0222a6ad209e8c848a1648075e0441ba069e",
|
|
44
44
|
"channel": "next"
|
|
45
45
|
}
|
|
46
46
|
}
|