cli: support setting the --parent-process-id in command shell (#193735)

This commit is contained in:
Connor Peet
2023-09-21 15:12:02 -07:00
committed by GitHub
parent e2bd761d52
commit 280c840f87
2 changed files with 9 additions and 1 deletions

View File

@@ -225,6 +225,9 @@ pub struct CommandShellArgs {
/// Require the given token string to be given in the handshake. /// Require the given token string to be given in the handshake.
#[clap(long)] #[clap(long)]
pub require_token: Option<String>, pub require_token: Option<String>,
/// Optional parent process id. If provided, the server will be stopped when the process of the given pid no longer exists
#[clap(long, hide = true)]
pub parent_process_id: Option<String>,
} }
#[derive(Args, Debug, Clone)] #[derive(Args, Debug, Clone)]

View File

@@ -136,6 +136,11 @@ impl ServiceContainer for TunnelServiceContainer {
pub async fn command_shell(ctx: CommandContext, args: CommandShellArgs) -> Result<i32, AnyError> { pub async fn command_shell(ctx: CommandContext, args: CommandShellArgs) -> Result<i32, AnyError> {
let platform = PreReqChecker::new().verify().await?; let platform = PreReqChecker::new().verify().await?;
let mut shutdown_reqs = vec![ShutdownRequest::CtrlC];
if let Some(p) = args.parent_process_id.and_then(|p| Pid::from_str(&p).ok()) {
shutdown_reqs.push(ShutdownRequest::ParentProcessKilled(p));
}
let mut params = ServeStreamParams { let mut params = ServeStreamParams {
log: ctx.log, log: ctx.log,
launcher_paths: ctx.paths, launcher_paths: ctx.paths,
@@ -144,7 +149,7 @@ pub async fn command_shell(ctx: CommandContext, args: CommandShellArgs) -> Resul
.require_token .require_token
.map(AuthRequired::VSDAWithToken) .map(AuthRequired::VSDAWithToken)
.unwrap_or(AuthRequired::VSDA), .unwrap_or(AuthRequired::VSDA),
exit_barrier: ShutdownRequest::create_rx([ShutdownRequest::CtrlC]), exit_barrier: ShutdownRequest::create_rx(shutdown_reqs),
code_server_args: (&ctx.args).into(), code_server_args: (&ctx.args).into(),
}; };