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

Function spawnService

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

Source from the content-addressed store, hash-verified

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

Callers 5

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

Calls 6

resolveWindowsCommandFunction · 0.90
deleteMethod · 0.80
spawnFunction · 0.70
logServiceFunction · 0.70
logErrorFunction · 0.70

Tested by

no test coverage detected