mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +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,
|
last_wifi_region: None,
|
||||||
eos_version_compat: Current::new().compat().clone(),
|
eos_version_compat: Current::new().compat().clone(),
|
||||||
lan_address,
|
lan_address,
|
||||||
tor_address: format!("http://{}", account.key.tor_address())
|
tor_address: format!("https://{}", account.key.tor_address())
|
||||||
.parse()
|
.parse()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
ip_info: BTreeMap::new(),
|
ip_info: BTreeMap::new(),
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use crate::disk::repair;
|
|||||||
use crate::init::SYSTEM_REBUILD_PATH;
|
use crate::init::SYSTEM_REBUILD_PATH;
|
||||||
use crate::logs::{fetch_logs, LogResponse, LogSource};
|
use crate::logs::{fetch_logs, LogResponse, LogSource};
|
||||||
use crate::shutdown::Shutdown;
|
use crate::shutdown::Shutdown;
|
||||||
use crate::system::SYSTEMD_UNIT;
|
|
||||||
use crate::util::display_none;
|
use crate::util::display_none;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ pub async fn logs(
|
|||||||
#[arg] cursor: Option<String>,
|
#[arg] cursor: Option<String>,
|
||||||
#[arg] before: bool,
|
#[arg] before: bool,
|
||||||
) -> Result<LogResponse, Error> {
|
) -> 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))]
|
#[command(display(display_none))]
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ fn deserialize_string_or_utf8_array<'de, D: serde::de::Deserializer<'de>>(
|
|||||||
String::from_utf8(
|
String::from_utf8(
|
||||||
std::iter::repeat_with(|| seq.next_element::<u8>().transpose())
|
std::iter::repeat_with(|| seq.next_element::<u8>().transpose())
|
||||||
.take_while(|a| a.is_some())
|
.take_while(|a| a.is_some())
|
||||||
.filter_map(|a| a)
|
.flatten()
|
||||||
.collect::<Result<Vec<u8>, _>>()?,
|
.collect::<Result<Vec<u8>, _>>()?,
|
||||||
)
|
)
|
||||||
.map_err(serde::de::Error::custom)
|
.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)
|
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)]
|
#[derive(Debug)]
|
||||||
pub enum LogSource {
|
pub enum LogSource {
|
||||||
Kernel,
|
Kernel,
|
||||||
Service(&'static str),
|
Unit(&'static str),
|
||||||
|
System,
|
||||||
Container(PackageId),
|
Container(PackageId),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const SYSTEM_UNIT: &str = "startd";
|
||||||
|
|
||||||
#[command(
|
#[command(
|
||||||
custom_cli(cli_logs(async, context(CliContext))),
|
custom_cli(cli_logs(async, context(CliContext))),
|
||||||
subcommands(self(logs_nofollow(async)), logs_follow),
|
subcommands(self(logs_nofollow(async)), logs_follow),
|
||||||
@@ -323,21 +332,15 @@ pub async fn cli_logs_generic_follow(
|
|||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
base_url.set_scheme(ws_scheme).or_else(|_| {
|
base_url
|
||||||
Err(Error::new(
|
.set_scheme(ws_scheme)
|
||||||
eyre!("Cannot set URL scheme"),
|
.map_err(|_| Error::new(eyre!("Cannot set URL scheme"), crate::ErrorKind::ParseUrl))?;
|
||||||
crate::ErrorKind::ParseUrl,
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
let (mut stream, _) =
|
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:
|
// 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?;
|
tokio_tungstenite::connect_async(format!("{}ws/rpc/{}", base_url, res.guid)).await?;
|
||||||
while let Some(log) = stream.try_next().await? {
|
while let Some(log) = stream.try_next().await? {
|
||||||
match log {
|
if let Message::Text(log) = log {
|
||||||
Message::Text(log) => {
|
println!("{}", serde_json::from_str::<LogEntry>(&log)?);
|
||||||
println!("{}", serde_json::from_str::<LogEntry>(&log)?);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,10 +364,15 @@ pub async fn journalctl(
|
|||||||
LogSource::Kernel => {
|
LogSource::Kernel => {
|
||||||
cmd.arg("-k");
|
cmd.arg("-k");
|
||||||
}
|
}
|
||||||
LogSource::Service(id) => {
|
LogSource::Unit(id) => {
|
||||||
cmd.arg("-u");
|
cmd.arg("-u");
|
||||||
cmd.arg(id);
|
cmd.arg(id);
|
||||||
}
|
}
|
||||||
|
LogSource::System => {
|
||||||
|
cmd.arg("-u");
|
||||||
|
cmd.arg(SYSTEM_UNIT);
|
||||||
|
cmd.arg(format!("_COMM={}", SYSTEM_UNIT));
|
||||||
|
}
|
||||||
LogSource::Container(id) => {
|
LogSource::Container(id) => {
|
||||||
cmd.arg(format!(
|
cmd.arg(format!(
|
||||||
"CONTAINER_NAME={}",
|
"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() {
|
if cursor.is_some() {
|
||||||
cmd.arg(&cursor_formatted);
|
cmd.arg(&cursor_formatted);
|
||||||
if before {
|
if before {
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ pub async fn logs_nofollow(
|
|||||||
_ctx: (),
|
_ctx: (),
|
||||||
(limit, cursor, before, _): (Option<usize>, Option<String>, bool, bool),
|
(limit, cursor, before, _): (Option<usize>, Option<String>, bool, bool),
|
||||||
) -> Result<LogResponse, Error> {
|
) -> 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))]
|
#[command(rpc_only, rename = "follow", display(display_none))]
|
||||||
@@ -147,7 +147,7 @@ pub async fn logs_follow(
|
|||||||
#[context] ctx: RpcContext,
|
#[context] ctx: RpcContext,
|
||||||
#[parent_data] (limit, _, _, _): (Option<usize>, Option<String>, bool, bool),
|
#[parent_data] (limit, _, _, _): (Option<usize>, Option<String>, bool, bool),
|
||||||
) -> Result<LogFollowResponse, Error> {
|
) -> 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>> {
|
fn event_handler(_event: AsyncEvent<'static>) -> BoxFuture<'static, Result<(), ConnError>> {
|
||||||
@@ -305,7 +305,7 @@ async fn torctl(
|
|||||||
.invoke(ErrorKind::Tor)
|
.invoke(ErrorKind::Tor)
|
||||||
.await?;
|
.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;
|
let mut tcp_stream = None;
|
||||||
for _ in 0..60 {
|
for _ in 0..60 {
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ use crate::util::serde::{display_serializable, IoFormat};
|
|||||||
use crate::util::{display_none, Invoke};
|
use crate::util::{display_none, Invoke};
|
||||||
use crate::{Error, ErrorKind, ResultExt};
|
use crate::{Error, ErrorKind, ResultExt};
|
||||||
|
|
||||||
pub const SYSTEMD_UNIT: &'static str = "startd";
|
|
||||||
|
|
||||||
#[command(subcommands(zram))]
|
#[command(subcommands(zram))]
|
||||||
pub async fn experimental() -> Result<(), Error> {
|
pub async fn experimental() -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -130,7 +128,7 @@ pub async fn logs_nofollow(
|
|||||||
_ctx: (),
|
_ctx: (),
|
||||||
(limit, cursor, before, _): (Option<usize>, Option<String>, bool, bool),
|
(limit, cursor, before, _): (Option<usize>, Option<String>, bool, bool),
|
||||||
) -> Result<LogResponse, Error> {
|
) -> 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))]
|
#[command(rpc_only, rename = "follow", display(display_none))]
|
||||||
@@ -138,7 +136,7 @@ pub async fn logs_follow(
|
|||||||
#[context] ctx: RpcContext,
|
#[context] ctx: RpcContext,
|
||||||
#[parent_data] (limit, _, _, _): (Option<usize>, Option<String>, bool, bool),
|
#[parent_data] (limit, _, _, _): (Option<usize>, Option<String>, bool, bool),
|
||||||
) -> Result<LogFollowResponse, Error> {
|
) -> Result<LogFollowResponse, Error> {
|
||||||
follow_logs(ctx, LogSource::Service(SYSTEMD_UNIT), limit).await
|
follow_logs(ctx, LogSource::System, limit).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command(
|
#[command(
|
||||||
|
|||||||
Reference in New Issue
Block a user