Skip to content

Commit

Permalink
Merge pull request #52 from Dstack-TEE/vm-pty
Browse files Browse the repository at this point in the history
teepod: Open a pty for vm console
  • Loading branch information
kvinwang authored Dec 12, 2024
2 parents 77c3a91 + 56aa1e9 commit b5bada6
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions teepod/src/app.rs
Original file line number Diff line number Diff line change
@@ -140,6 +140,10 @@ impl App {
work_dir
.set_started(true)
.with_context(|| format!("Failed to set started for VM {id}"))?;
if work_dir.serial_pty().exists() {
// remove the existing pty
fs::remove_file(&work_dir.serial_pty())?;
}
let process_config = vm_config.config_qemu(&self.config.qemu_path, &work_dir)?;
self.supervisor
.deploy(process_config)
14 changes: 11 additions & 3 deletions teepod/src/app/qemu.rs
Original file line number Diff line number Diff line change
@@ -156,6 +156,7 @@ impl VmConfig {
pub fn config_qemu(&self, qemu: &Path, workdir: impl AsRef<Path>) -> Result<ProcessConfig> {
let workdir = VmWorkDir::new(workdir);
let serial_file = workdir.serial_file();
let serial_pty = workdir.serial_pty();
let shared_dir = workdir.shared_dir();
let disk_size = format!("{}G", self.manifest.disk_size);
let hda_path = workdir.hda_path();
@@ -172,9 +173,12 @@ impl VmConfig {
command.arg("-m").arg(format!("{}M", self.manifest.memory));
command.arg("-nographic");
command.arg("-nodefaults");
command
.arg("-serial")
.arg(format!("file:{}", serial_file.display()));
command.arg("-chardev").arg(format!(
"pty,id=com0,path={},logfile={}",
serial_pty.display(),
serial_file.display()
));
command.arg("-serial").arg("chardev:com0");
command.arg("-kernel").arg(&self.image.kernel);
command.arg("-initrd").arg(&self.image.initrd);
command
@@ -334,6 +338,10 @@ impl VmWorkDir {
self.workdir.join("serial.log")
}

pub fn serial_pty(&self) -> PathBuf {
self.workdir.join("serial.pty")
}

pub fn stdout_file(&self) -> PathBuf {
self.workdir.join("stdout.log")
}

0 comments on commit b5bada6

Please sign in to comment.