oseda_cli/
net.rs

1use std::{error::Error, fmt::format, process::Command};
2
3pub fn get_status(host: &str) -> Result<reqwest::StatusCode, Box<dyn Error>> {
4    let response = reqwest::blocking::get(host)?;
5
6    return Ok(response.status());
7}
8
9// this will only work on linux sadly
10pub fn kill_port(port_num: u16) -> Result<(), Box<dyn Error>> {
11    // kill $(lsof -t -i:PORT_NUM)
12
13    let lsof_out = Command::new("lsof")
14        .arg("-t")
15        .arg(format!("-i:{}", port_num))
16        .output()?;
17
18    let procs_on_port = String::from_utf8(lsof_out.stdout)?;
19
20    for pid in procs_on_port.lines() {
21        Command::new("kill").arg(pid).output()?;
22    }
23
24    Ok(())
25}