MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / spawnService

Function spawnService

scripts/dev-static.mjs:219–261  ·  view source on GitHub ↗
(name, command, args, options = {})

Source from the content-addressed store, hash-verified

217let shuttingDown = false;
218
219function spawnService(name, command, args, options = {}) {
220 const proc = spawn(
221 resolveWindowsCommand(command),
222 args,
223 getProcessTreeSpawnOptions({
224 stdio: ["ignore", "pipe", "pipe"],
225 env: { ...process.env, ...options.env },
226 cwd: options.cwd,
227 }),
228 );
229
230 const color = options.color || c.reset;
231
232 proc.stdout.on("data", (data) => {
233 data
234 .toString()
235 .split("\n")
236 .filter(Boolean)
237 .forEach((line) => logService(name, line.trim(), color));
238 });
239
240 proc.stderr.on("data", (data) => {
241 data
242 .toString()
243 .split("\n")
244 .filter(Boolean)
245 .forEach((line) => logService(name, line.trim(), c.yellow));
246 });
247
248 proc.on("error", (error) => {
249 logError(`${name} failed to start: ${error.message}`);
250 });
251
252 proc.on("exit", (code) => {
253 if (code !== 0 && code !== null && !shuttingDown) {
254 logService(name, `Exited with code ${code}`, c.red);
255 }
256 processes.delete(name);
257 });
258
259 processes.set(name, proc);
260 return proc;
261}
262
263async function waitForService(name, url, timeoutMs = 30000) {
264 const start = Date.now();

Callers 5

startAgentServerFunction · 0.70
startAutomationBackendFunction · 0.70
startStaticServerFunction · 0.70
startIngressFunction · 0.70

Calls 5

resolveWindowsCommandFunction · 0.90
spawnFunction · 0.70
logServiceFunction · 0.70
logErrorFunction · 0.70

Tested by

no test coverage detected