Archived
1
0

Get boostrap stuff forking

They don't run yet but seem to be forking correctly now.
This commit is contained in:
Asher 2019-01-22 18:28:54 -06:00 committed by Kyle Carberry
parent b1cd5c142f
commit 8a789ac957
No known key found for this signature in database
GPG Key ID: A0409BDB6B0B3EDB
6 changed files with 32 additions and 11 deletions

View File

@ -260,7 +260,6 @@ export class Logger {
if (name) {
this.nameColor = hashStringToColor(name);
}
this.info(`Log level: ${process.env.LOG_LEVEL || "info"}`);
if (process.env.LOG_LEVEL) {
switch (process.env.LOG_LEVEL) {
case "debug": this.level = Level.Debug; break;

View File

@ -1,6 +1,6 @@
import * as events from "events";
import * as stream from "stream";
import { SendableConnection } from "../common/connection";
import { ReadWriteConnection } from "../common/connection";
import { ShutdownSessionMessage, ClientMessage, WriteToSessionMessage, ResizeSessionTTYMessage, TTYDimensions as ProtoTTYDimensions, ConnectionOutputMessage, ConnectionCloseMessage } from "../proto";
export interface TTYDimensions {
@ -40,11 +40,14 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess {
private _killed: boolean = false;
public constructor(
private readonly connection: SendableConnection,
private readonly connection: ReadWriteConnection,
private readonly id: number,
private readonly hasTty: boolean = false,
) {
super();
this.connection.onMessage((message) => {
this.emit("message", message);
});
if (!this.hasTty) {
delete this.resize;
@ -131,7 +134,7 @@ export class ServerSocket extends events.EventEmitter implements Socket {
private _connecting: boolean = true;
public constructor(
private readonly connection: SendableConnection,
private readonly connection: ReadWriteConnection,
private readonly id: number,
connectCallback?: () => void,
) {

View File

@ -46,7 +46,7 @@ export class CP {
public fork = (modulePath: string, args?: ReadonlyArray<string> | cp.ForkOptions, options?: cp.ForkOptions): cp.ChildProcess => {
//@ts-ignore
return this.client.fork(modulePath, args, options);
return this.client.fork(options && options.env && options.env.AMD_ENTRYPOINT || modulePath, args, options);
}
public spawn = (command: string, args?: ReadonlyArray<string> | cp.SpawnOptions, options?: cp.SpawnOptions): cp.ChildProcess => {

View File

@ -3,7 +3,7 @@ import * as net from "net";
import * as nodePty from "node-pty";
import * as stream from "stream";
import { TextEncoder } from "text-encoding";
import { NewSessionMessage, ServerMessage, SessionDoneMessage, SessionOutputMessage, ShutdownSessionMessage, IdentifySessionMessage, ClientMessage, NewConnectionMessage, ConnectionEstablishedMessage, NewConnectionFailureMessage, ConnectionCloseMessage, ConnectionOutputMessage } from "../proto";
import { NewSessionMessage, ServerMessage, SessionDoneMessage, SessionOutputMessage, IdentifySessionMessage, NewConnectionMessage, ConnectionEstablishedMessage, NewConnectionFailureMessage, ConnectionCloseMessage, ConnectionOutputMessage } from "../proto";
import { SendableConnection } from "../common/connection";
import { ServerOptions } from "./server";
@ -16,7 +16,7 @@ export interface Process {
killed?: boolean;
on(event: "data", cb: (data: string) => void): void;
on(event: 'exit', listener: (exitCode: number, signal?: number) => void): void;
on(event: "exit", listener: (exitCode: number, signal?: number) => void): void;
write(data: string | Uint8Array): void;
resize?(cols: number, rows: number): void;
kill(signal?: string): void;
@ -170,4 +170,4 @@ export const handleNewConnection = (connection: SendableConnection, newConnectio
});
return socket;
}
};

View File

@ -44,14 +44,33 @@ export const createApp = (registerMiddleware?: (app: express.Application) => voi
const server = new Server(connection, options ? {
...options,
forkProvider: (message: NewSessionMessage): ChildProcess => {
let proc: ChildProcess;
const command = message.getCommand();
const childLogger = logger.named(command.split("/").pop()!);
childLogger.debug("Forking...", field("module", command));
let proc: ChildProcess;
if (message.getIsBootstrapFork()) {
proc = forkModule(message.getCommand());
proc = forkModule(command);
} else {
throw new Error("No support for non bootstrap-forking yet");
}
proc.stdout.on("data", (message) => {
childLogger.debug("stdout", field("message", message.toString().trim()));
});
proc.stderr.on("data", (message) => {
childLogger.debug("stderr", field("message", message.toString().trim()));
});
proc.stdin.on("data", (message) => {
childLogger.debug("stdin", field("message", message.toString().trim()));
});
proc.on("exit", (exitCode) => {
childLogger.debug(`Exited with ${exitCode}`);
});
return proc;
},
} : undefined);

View File

@ -29,7 +29,7 @@ export class SharedProcess {
private activeProcess: ChildProcess | undefined;
private ipcHandler: StdioIpcHandler | undefined;
private readonly onStateEmitter: Emitter<SharedProcessEvent>;
private readonly logger = logger.named("SHDR PROC");
private readonly logger = logger.named("SHRD PROC");
public constructor(
private readonly userDataDir: string,