mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
fix: Add in logging for the podman in the system logs (#2451)
* fix: Add in logging for the podman in the system logs * https as default for main tor address --------- Co-authored-by: agent <kn0wmad@protonmail.com>
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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<String>,
|
||||
#[arg] before: bool,
|
||||
) -> Result<LogResponse, Error> {
|
||||
Ok(fetch_logs(LogSource::Service(SYSTEMD_UNIT), limit, cursor, before).await?)
|
||||
Ok(fetch_logs(LogSource::System, limit, cursor, before).await?)
|
||||
}
|
||||
|
||||
#[command(display(display_none))]
|
||||
|
||||
@@ -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::<u8>().transpose())
|
||||
.take_while(|a| a.is_some())
|
||||
.filter_map(|a| a)
|
||||
.flatten()
|
||||
.collect::<Result<Vec<u8>, _>>()?,
|
||||
)
|
||||
.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,22 +332,16 @@ 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) => {
|
||||
if let Message::Text(log) = log {
|
||||
println!("{}", serde_json::from_str::<LogEntry>(&log)?);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -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 {
|
||||
|
||||
@@ -139,7 +139,7 @@ pub async fn logs_nofollow(
|
||||
_ctx: (),
|
||||
(limit, cursor, before, _): (Option<usize>, Option<String>, bool, bool),
|
||||
) -> Result<LogResponse, Error> {
|
||||
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<usize>, Option<String>, bool, bool),
|
||||
) -> Result<LogFollowResponse, Error> {
|
||||
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 {
|
||||
|
||||
@@ -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<usize>, Option<String>, bool, bool),
|
||||
) -> Result<LogResponse, Error> {
|
||||
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<usize>, Option<String>, bool, bool),
|
||||
) -> Result<LogFollowResponse, Error> {
|
||||
follow_logs(ctx, LogSource::Service(SYSTEMD_UNIT), limit).await
|
||||
follow_logs(ctx, LogSource::System, limit).await
|
||||
}
|
||||
|
||||
#[command(
|
||||
|
||||
Reference in New Issue
Block a user