Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions hum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ fn now_ms() -> u64 {
}

fn probe_thrum(sock: &Path) -> Result<()> {
use std::io::{Read, Write};
use std::io::Read;
use std::os::unix::net::UnixStream;
use std::time::Duration;
if !sock.exists() {
Expand All @@ -317,8 +317,6 @@ fn probe_thrum(sock: &Path) -> Result<()> {
let mut s = UnixStream::connect(sock)
.map_err(|e| anyhow::anyhow!("connect refused ({e}) — stale socket, humd crashed"))?;
s.set_read_timeout(Some(Duration::from_secs(1)))?;
s.set_write_timeout(Some(Duration::from_secs(1)))?;
s.write_all(b"{\"chi\":\"hello\",\"sid\":\"hum-doctor-probe\"}\n")?;
let mut buf = [0u8; 256];
match s.read(&mut buf) {
Ok(0) => anyhow::bail!("socket closed without breath"),
Expand Down
4 changes: 1 addition & 3 deletions humctl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn logs(lines: u32) -> Result<()> {

fn health() -> Result<()> {
let sock = hum_paths::thrum_sock_resolved();
use std::io::{Read, Write};
use std::io::Read;
use std::os::unix::net::UnixStream;
use std::time::Duration;
if !sock.exists() {
Expand All @@ -161,8 +161,6 @@ fn health() -> Result<()> {
let mut s =
UnixStream::connect(&sock).with_context(|| format!("connect {}", sock.display()))?;
s.set_read_timeout(Some(Duration::from_secs(1)))?;
s.set_write_timeout(Some(Duration::from_secs(1)))?;
s.write_all(b"{\"chi\":\"hello\",\"sid\":\"humctl-health\"}\n")?;
let mut buf = [0u8; 256];
match s.read(&mut buf) {
Ok(0) => bail!("socket closed without breath"),
Expand Down
34 changes: 29 additions & 5 deletions humd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,17 +555,23 @@ async fn autoupdate_check_once() -> Result<bool> {
return Ok(false);
}
info!(local = %stamped, upstream = %upstream_trim, "autoupdate.newer.found");
let status = tokio::process::Command::new("bash")
.arg("-c")
.arg("curl -fsSL https://raw.githubusercontent.com/adiled/hum/main/install | bash")
.status()
.await?;
let status = installer_outliving_humd(
"curl -fsSL https://raw.githubusercontent.com/adiled/hum/main/install | bash",
)
.status()
.await?;
if !status.success() {
anyhow::bail!("installer exited with {status}");
}
Ok(true)
}

fn installer_outliving_humd(script: &str) -> tokio::process::Command {
let mut cmd = tokio::process::Command::new("bash");
cmd.arg("-c").arg(script).process_group(0);
cmd
}

fn parse_tag_name(body: &str) -> Option<String> {
let needle = "\"tag_name\":";
let start = body.find(needle)? + needle.len();
Expand Down Expand Up @@ -2291,3 +2297,21 @@ const BREATH_EVERY: Duration = Duration::from_secs(2);
fn parse_humd_id(s: &str) -> Option<ensemble::Hid> {
ensemble::Hid::from_hex(s).ok()
}

#[cfg(test)]
mod autoupdate_tests {
use super::*;

#[tokio::test]
async fn the_installer_leads_its_own_process_group_so_a_bootout_of_humd_spares_it() {
let out = installer_outliving_humd("echo $$ $(ps -o pgid= -p $$)")
.output()
.await
.unwrap();
let said = String::from_utf8(out.stdout).unwrap();
let mut words = said.split_whitespace();
let pid = words.next().unwrap();
let pgid = words.next().unwrap();
assert_eq!(pid, pgid);
}
}
Loading