diff --git a/backend/src/db/model.rs b/backend/src/db/model.rs index b23a3b149..af6147ab6 100644 --- a/backend/src/db/model.rs +++ b/backend/src/db/model.rs @@ -45,7 +45,7 @@ impl Database { last_wifi_region: None, eos_version_compat: Current::new().compat().clone(), lan_address, - tor_address: format!("http://{}", account.key.tor_address()) + tor_address: format!("https://{}", account.key.tor_address()) .parse() .unwrap(), ip_info: BTreeMap::new(), diff --git a/backend/src/diagnostic.rs b/backend/src/diagnostic.rs index 1d4c3bcf5..b4f99c7ee 100644 --- a/backend/src/diagnostic.rs +++ b/backend/src/diagnostic.rs @@ -9,7 +9,6 @@ use crate::disk::repair; use crate::init::SYSTEM_REBUILD_PATH; use crate::logs::{fetch_logs, LogResponse, LogSource}; use crate::shutdown::Shutdown; -use crate::system::SYSTEMD_UNIT; use crate::util::display_none; use crate::Error; @@ -29,7 +28,7 @@ pub async fn logs( #[arg] cursor: Option, #[arg] before: bool, ) -> Result { - Ok(fetch_logs(LogSource::Service(SYSTEMD_UNIT), limit, cursor, before).await?) + Ok(fetch_logs(LogSource::System, limit, cursor, before).await?) } #[command(display(display_none))] diff --git a/backend/src/logs.rs b/backend/src/logs.rs index 30d73f4d7..5725a3b72 100644 --- a/backend/src/logs.rs +++ b/backend/src/logs.rs @@ -198,7 +198,7 @@ fn deserialize_string_or_utf8_array<'de, D: serde::de::Deserializer<'de>>( String::from_utf8( std::iter::repeat_with(|| seq.next_element::().transpose()) .take_while(|a| a.is_some()) - .filter_map(|a| a) + .flatten() .collect::, _>>()?, ) .map_err(serde::de::Error::custom) @@ -207,13 +207,22 @@ fn deserialize_string_or_utf8_array<'de, D: serde::de::Deserializer<'de>>( deserializer.deserialize_any(Visitor) } +/// Defining how we are going to filter on a journalctl cli log. +/// Kernal: (-k --dmesg Show kernel message log from the current boot) +/// Unit: ( -u --unit=UNIT Show logs from the specified unit +/// --user-unit=UNIT Show logs from the specified user unit)) +/// System: Unit is startd, but we also filter on the comm +/// Container: Filtering containers, like podman/docker is done by filtering on the CONTAINER_NAME #[derive(Debug)] pub enum LogSource { Kernel, - Service(&'static str), + Unit(&'static str), + System, Container(PackageId), } +pub const SYSTEM_UNIT: &str = "startd"; + #[command( custom_cli(cli_logs(async, context(CliContext))), subcommands(self(logs_nofollow(async)), logs_follow), @@ -323,21 +332,15 @@ pub async fn cli_logs_generic_follow( .into()) } }; - base_url.set_scheme(ws_scheme).or_else(|_| { - Err(Error::new( - eyre!("Cannot set URL scheme"), - crate::ErrorKind::ParseUrl, - )) - })?; + base_url + .set_scheme(ws_scheme) + .map_err(|_| Error::new(eyre!("Cannot set URL scheme"), crate::ErrorKind::ParseUrl))?; let (mut stream, _) = // base_url is "http://127.0.0.1/", with a trailing slash, so we don't put a leading slash in this path: tokio_tungstenite::connect_async(format!("{}ws/rpc/{}", base_url, res.guid)).await?; while let Some(log) = stream.try_next().await? { - match log { - Message::Text(log) => { - println!("{}", serde_json::from_str::(&log)?); - } - _ => (), + if let Message::Text(log) = log { + println!("{}", serde_json::from_str::(&log)?); } } @@ -361,10 +364,15 @@ pub async fn journalctl( LogSource::Kernel => { cmd.arg("-k"); } - LogSource::Service(id) => { + LogSource::Unit(id) => { cmd.arg("-u"); cmd.arg(id); } + LogSource::System => { + cmd.arg("-u"); + cmd.arg(SYSTEM_UNIT); + cmd.arg(format!("_COMM={}", SYSTEM_UNIT)); + } LogSource::Container(id) => { cmd.arg(format!( "CONTAINER_NAME={}", @@ -373,7 +381,7 @@ pub async fn journalctl( } }; - let cursor_formatted = format!("--after-cursor={}", cursor.clone().unwrap_or("")); + let cursor_formatted = format!("--after-cursor={}", cursor.unwrap_or("")); if cursor.is_some() { cmd.arg(&cursor_formatted); if before { diff --git a/backend/src/net/tor.rs b/backend/src/net/tor.rs index d1d8f0b80..9926d3c6c 100644 --- a/backend/src/net/tor.rs +++ b/backend/src/net/tor.rs @@ -139,7 +139,7 @@ pub async fn logs_nofollow( _ctx: (), (limit, cursor, before, _): (Option, Option, bool, bool), ) -> Result { - fetch_logs(LogSource::Service(SYSTEMD_UNIT), limit, cursor, before).await + fetch_logs(LogSource::Unit(SYSTEMD_UNIT), limit, cursor, before).await } #[command(rpc_only, rename = "follow", display(display_none))] @@ -147,7 +147,7 @@ pub async fn logs_follow( #[context] ctx: RpcContext, #[parent_data] (limit, _, _, _): (Option, Option, bool, bool), ) -> Result { - follow_logs(ctx, LogSource::Service(SYSTEMD_UNIT), limit).await + follow_logs(ctx, LogSource::Unit(SYSTEMD_UNIT), limit).await } fn event_handler(_event: AsyncEvent<'static>) -> BoxFuture<'static, Result<(), ConnError>> { @@ -305,7 +305,7 @@ async fn torctl( .invoke(ErrorKind::Tor) .await?; - let logs = journalctl(LogSource::Service(SYSTEMD_UNIT), 0, None, false, true).await?; + let logs = journalctl(LogSource::Unit(SYSTEMD_UNIT), 0, None, false, true).await?; let mut tcp_stream = None; for _ in 0..60 { diff --git a/backend/src/system.rs b/backend/src/system.rs index 6f05b6b73..65dfbd463 100644 --- a/backend/src/system.rs +++ b/backend/src/system.rs @@ -23,8 +23,6 @@ use crate::util::serde::{display_serializable, IoFormat}; use crate::util::{display_none, Invoke}; use crate::{Error, ErrorKind, ResultExt}; -pub const SYSTEMD_UNIT: &'static str = "startd"; - #[command(subcommands(zram))] pub async fn experimental() -> Result<(), Error> { Ok(()) @@ -130,7 +128,7 @@ pub async fn logs_nofollow( _ctx: (), (limit, cursor, before, _): (Option, Option, bool, bool), ) -> Result { - fetch_logs(LogSource::Service(SYSTEMD_UNIT), limit, cursor, before).await + fetch_logs(LogSource::System, limit, cursor, before).await } #[command(rpc_only, rename = "follow", display(display_none))] @@ -138,7 +136,7 @@ pub async fn logs_follow( #[context] ctx: RpcContext, #[parent_data] (limit, _, _, _): (Option, Option, bool, bool), ) -> Result { - follow_logs(ctx, LogSource::Service(SYSTEMD_UNIT), limit).await + follow_logs(ctx, LogSource::System, limit).await } #[command(