From 54f34def2c0eac66ae6e085c7942f406d687d285 Mon Sep 17 00:00:00 2001 From: Markus Zehnder Date: Sun, 31 Aug 2025 20:58:43 +0200 Subject: [PATCH] refactor: rename sysinfo tool to aster-sysinfo (#16) The sysinfo name was too generic and misleading. This tool provides sensor values from the system for `asterctl` and is not a generic system information tool. --- .github/workflows/build.yml | 2 +- .idea/dictionaries/project.xml | 7 +++ AOOstar-rs.iml | 4 +- CHANGELOG.md | 3 +- Cargo.lock | 63 +++++++++---------- crates/{sysinfo => aster-sysinfo}/Cargo.toml | 4 +- .../{sysinfo => aster-sysinfo}/LICENSE-APACHE | 0 crates/{sysinfo => aster-sysinfo}/LICENSE-MIT | 0 crates/{sysinfo => aster-sysinfo}/README.md | 4 +- crates/{sysinfo => aster-sysinfo}/src/main.rs | 19 ++++-- crates/asterctl-lcd/Cargo.toml | 2 +- crates/asterctl/Cargo.toml | 4 +- docs/SUMMARY.md | 2 +- docs/installation.md | 4 +- docs/linux/README.md | 34 ++++++++-- docs/sensor/README.md | 2 +- docs/sensor/provider/sysinfo.md | 10 +-- linux/aster-sysinfo.service | 44 +++++++++++++ 18 files changed, 144 insertions(+), 64 deletions(-) create mode 100644 .idea/dictionaries/project.xml rename crates/{sysinfo => aster-sysinfo}/Cargo.toml (90%) rename crates/{sysinfo => aster-sysinfo}/LICENSE-APACHE (100%) rename crates/{sysinfo => aster-sysinfo}/LICENSE-MIT (100%) rename crates/{sysinfo => aster-sysinfo}/README.md (93%) rename crates/{sysinfo => aster-sysinfo}/src/main.rs (98%) create mode 100644 linux/aster-sysinfo.service diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1ff9acd..e96ddb9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -106,7 +106,7 @@ jobs: ls -la target/release mkdir -p ${GITHUB_WORKSPACE}/${{env.BIN_OUTPUT_PATH }} cp target/release/${{ env.APP_NAME }} ${GITHUB_WORKSPACE}/${{ env.BIN_OUTPUT_PATH }} - cp target/release/sysinfo ${GITHUB_WORKSPACE}/${{ env.BIN_OUTPUT_PATH }} + cp target/release/aster-sysinfo ${GITHUB_WORKSPACE}/${{ env.BIN_OUTPUT_PATH }} cp linux/*.service ${GITHUB_WORKSPACE}/${{ env.BIN_OUTPUT_PATH }} cp -r cfg ${GITHUB_WORKSPACE}/${{ env.BIN_OUTPUT_PATH }} echo "VERSION=${{ env.APP_VERSION }}" > ${GITHUB_WORKSPACE}/${{ env.BIN_OUTPUT_PATH }}/version.txt diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml new file mode 100644 index 0000000..ef4c95e --- /dev/null +++ b/.idea/dictionaries/project.xml @@ -0,0 +1,7 @@ + + + + zehnder + + + \ No newline at end of file diff --git a/AOOstar-rs.iml b/AOOstar-rs.iml index 94c628b..6f4533c 100644 --- a/AOOstar-rs.iml +++ b/AOOstar-rs.iml @@ -6,10 +6,10 @@ - + - + diff --git a/CHANGELOG.md b/CHANGELOG.md index b020938..c80c017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,12 +12,13 @@ _Changes in the next release_ ### Fixed - Misplaced text sensors in custom panels ([#11](https://github.com/zehnm/aoostar-rs/issues/11)). - Wrong start position for circular progress (fan) sensor using a counter-clockwise direction ([#12](https://github.com/zehnm/aoostar-rs/issues/12)). -- sysinfo tool: make sensor file world-readable, create all parent directories. +- aster-sysinfo tool: make sensor file world-readable, create all parent directories. ### Added - Simple sensor panel with a file-based data source ([#6](https://github.com/zehnm/aoostar-rs/issues/6)). - Initial support for fan-, progress-, & pointer-sensors ([#8](https://github.com/zehnm/aoostar-rs/pull/8)). - Use [mdBook](https://rust-lang.github.io/mdBook/) for documentation and publish user guide to GitHub pages ([#10](https://github.com/zehnm/aoostar-rs/pull/10)). +- Initial `aster-sysinfo` tool for providing sensor values in a text file for `asterctl`. ### Changed - Project structure using a Cargo workspace. diff --git a/Cargo.lock b/Cargo.lock index a912d6f..466178e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,9 +130,22 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +[[package]] +name = "aster-sysinfo" +version = "0.2.0" +dependencies = [ + "clap", + "env_logger", + "itertools 0.14.0", + "log", + "regex", + "sysinfo", + "tempfile", +] + [[package]] name = "asterctl" -version = "0.1.0" +version = "0.2.0" dependencies = [ "ab_glyph", "anyhow", @@ -152,7 +165,7 @@ dependencies = [ [[package]] name = "asterctl-lcd" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "bytes", @@ -192,9 +205,9 @@ dependencies = [ [[package]] name = "bit_field" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" +checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6" [[package]] name = "bitflags" @@ -273,9 +286,9 @@ checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "clap" -version = "4.5.45" +version = "4.5.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc0e74a703892159f5ae7d3aac52c8e6c392f5ae5f359c70b5881d60aaac318" +checksum = "2c5e4fcf9c21d2e544ca1ee9d8552de13019a42aa7dbf32747fa7aaf1df76e57" dependencies = [ "clap_builder", "clap_derive", @@ -283,9 +296,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.44" +version = "4.5.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e7f4214277f3c7aa526a59dd3fbe306a370daee1f8b7b8c987069cd8e888a8" +checksum = "fecb53a0e6fcfb055f686001bc2e2592fa527efaf38dbe81a6a9563562e57d41" dependencies = [ "anstream", "anstyle", @@ -558,7 +571,7 @@ dependencies = [ "cfg-if", "libc", "r-efi", - "wasi 0.14.2+wasi-0.2.4", + "wasi 0.14.3+wasi-0.2.4", ] [[package]] @@ -624,9 +637,9 @@ dependencies = [ [[package]] name = "image-webp" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6970fe7a5300b4b42e62c52efa0187540a5bef546c60edaf554ef595d2e6f0b" +checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3" dependencies = [ "byteorder-lite", "quick-error", @@ -1656,19 +1669,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sysinfo" -version = "0.1.0" -dependencies = [ - "clap", - "env_logger", - "itertools 0.14.0", - "log", - "regex", - "sysinfo 0.37.0", - "tempfile", -] - [[package]] name = "sysinfo" version = "0.37.0" @@ -1868,11 +1868,11 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" -version = "0.14.2+wasi-0.2.4" +version = "0.14.3+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95" dependencies = [ - "wit-bindgen-rt", + "wit-bindgen", ] [[package]] @@ -2248,13 +2248,10 @@ dependencies = [ ] [[package]] -name = "wit-bindgen-rt" -version = "0.39.0" +name = "wit-bindgen" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" -dependencies = [ - "bitflags 2.9.3", -] +checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814" [[package]] name = "zerocopy" diff --git a/crates/sysinfo/Cargo.toml b/crates/aster-sysinfo/Cargo.toml similarity index 90% rename from crates/sysinfo/Cargo.toml rename to crates/aster-sysinfo/Cargo.toml index 81b72f1..c4dbb4d 100644 --- a/crates/sysinfo/Cargo.toml +++ b/crates/aster-sysinfo/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "sysinfo" -version = "0.1.0" +name = "aster-sysinfo" +version = "0.2.0" description = "System sensor provider for asterctl" rust-version.workspace = true diff --git a/crates/sysinfo/LICENSE-APACHE b/crates/aster-sysinfo/LICENSE-APACHE similarity index 100% rename from crates/sysinfo/LICENSE-APACHE rename to crates/aster-sysinfo/LICENSE-APACHE diff --git a/crates/sysinfo/LICENSE-MIT b/crates/aster-sysinfo/LICENSE-MIT similarity index 100% rename from crates/sysinfo/LICENSE-MIT rename to crates/aster-sysinfo/LICENSE-MIT diff --git a/crates/sysinfo/README.md b/crates/aster-sysinfo/README.md similarity index 93% rename from crates/sysinfo/README.md rename to crates/aster-sysinfo/README.md index e36c5c6..68714df 100644 --- a/crates/sysinfo/README.md +++ b/crates/aster-sysinfo/README.md @@ -37,11 +37,11 @@ Options: Single test run with printing all sensors in the console: ```shell -sysinfo --console +aster-sysinfo --console ``` Normal mode providing sensor values for `asterctl` in `/tmp/sensors/sysinfo.txt` every 3 seconds: ```shell -sysinfo --refresh 3 --out /tmp/sensors/sysinfo.txt +aster-sysinfo --refresh 3 --out /tmp/sensors/aster-sysinfo.txt ``` diff --git a/crates/sysinfo/src/main.rs b/crates/aster-sysinfo/src/main.rs similarity index 98% rename from crates/sysinfo/src/main.rs rename to crates/aster-sysinfo/src/main.rs index 5169284..26235cd 100644 --- a/crates/sysinfo/src/main.rs +++ b/crates/aster-sysinfo/src/main.rs @@ -20,7 +20,7 @@ use std::process::{Command, exit}; use std::thread::sleep; use std::time::{Duration, Instant}; use sysinfo::{Components, DiskKind, Disks, Networks, System}; -use tempfile::{Builder, NamedTempFile}; +use tempfile::Builder; /// Proof of concept sensor value collection for the asterctl screen control tool. #[derive(Parser, Debug)] @@ -66,7 +66,9 @@ fn main() -> Result<(), Box> { #[cfg(not(target_os = "linux"))] let use_smartctl = false; - if let Some(out_file) = &args.out && let Some(parent) = out_file.parent() { + if let Some(out_file) = &args.out + && let Some(parent) = out_file.parent() + { fs::create_dir_all(parent)?; } let mut sensors = HashMap::with_capacity(64); @@ -81,7 +83,10 @@ fn main() -> Result<(), Box> { } if !refresh.is_zero() { - info!("Starting sysinfo with refresh={}ms", refresh.as_millis()); + info!( + "Starting aster-sysinfo with refresh={}ms", + refresh.as_millis() + ); } loop { @@ -91,7 +96,7 @@ fn main() -> Result<(), Box> { sysinfo_source.update_sensors(&mut sensors)?; if !disk_refresh.is_zero() && disk_refresh_time.elapsed() > disk_refresh { - info!("Refreshing individual disks"); + debug!("Refreshing individual disks"); update_linux_storage_sensors(&mut sensors, use_smartctl)?; disk_refresh_time = Instant::now(); } @@ -137,7 +142,9 @@ fn write_sensor_file( fs::create_dir_all(temp_path)?; debug!("Creating a new named temp file in {temp_path:?}"); - Builder::new().permissions(all_read_perm).tempfile_in(temp_path)? + Builder::new() + .permissions(all_read_perm) + .tempfile_in(temp_path)? } else { debug!("Creating a new named temp file"); Builder::new().permissions(all_read_perm).tempfile()? @@ -187,6 +194,7 @@ impl SysinfoSource { pub fn refresh(&mut self) { self.sys.refresh_all(); + debug!("Refreshing disks, components, networks"); // TODO research "remove_not_listed_###" refresh parameter self.disks.refresh(false); self.components.refresh(false); @@ -202,6 +210,7 @@ impl SysinfoSource { &self, sensors: &mut HashMap, ) -> Result<(), Box> { + debug!("Refreshing sensors"); for cpu in self.sys.cpus() { add_sensor( sensors, diff --git a/crates/asterctl-lcd/Cargo.toml b/crates/asterctl-lcd/Cargo.toml index 4e9897c..b7d140b 100644 --- a/crates/asterctl-lcd/Cargo.toml +++ b/crates/asterctl-lcd/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "asterctl-lcd" -version = "0.1.0" +version = "0.2.0" description = "AOOSTAR WTR MAX / GEM12+ PRO screen protocol" rust-version.workspace = true diff --git a/crates/asterctl/Cargo.toml b/crates/asterctl/Cargo.toml index 58e414f..884b5cd 100644 --- a/crates/asterctl/Cargo.toml +++ b/crates/asterctl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "asterctl" -version = "0.1.0" +version = "0.2.0" description = "AOOSTAR WTR MAX Screen Control tool" readme = "../../README.md" @@ -11,7 +11,7 @@ license.workspace = true repository.workspace = true [dependencies] -asterctl-lcd = { path = "../asterctl-lcd", version = "0.1.0" } +asterctl-lcd = { path = "../asterctl-lcd", version = "0.2.0" } anyhow = "1.0.98" clap = { version = "4.5.42", features = ["derive"] } diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 420146c..f207468 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -21,7 +21,7 @@ - [Sensor Value Provider](sensor/provider/README.md) - [Text File Data Source](sensor/provider/text_file.md) - [Shell Scripts](sensor/provider/shell_scripts.md) - - [Sysinfo Tool](sensor/provider/sysinfo.md) + - [aster-sysinfo Tool](sensor/provider/sysinfo.md) diff --git a/docs/installation.md b/docs/installation.md index 002ad51..5e6c4d1 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -8,11 +8,11 @@ Please note that only Linux has been tested so far. Executable binaries are available for download on the [GitHub Releases page](https://github.com/zehnm/aoostar-rs/releases). Download the binary for your platform (only Linux available at the moment) and extract the archive. -The archive contains the `asterctl` and `sysinfo` executables which you can run. +The archive contains the `asterctl` and `aster-sysinfo` executables which you can run. ## Build from source using Rust -To build the `asterctl` and `sysinfo` executables from source, you will first need to install Rust and Cargo. +To build the `asterctl` and `aster-sysinfo` executables from source, you will first need to install Rust and Cargo. Follow the instructions on the [Rust installation page](https://www.rust-lang.org/tools/install). At least Rust version 1.88 is required. diff --git a/docs/linux/README.md b/docs/linux/README.md index b3c145d..29e7840 100644 --- a/docs/linux/README.md +++ b/docs/linux/README.md @@ -1,26 +1,27 @@ -# Linux systemd Service +# Linux systemd Services + +## Switch Off LCD on Boot The systemd unit [lcd-off.service](https://github.com/zehnm/aoostar-rs/blob/main/linux/lcd-off.service) can be installed to automatically switch off the embedded LCD on boot. -The unit file has been tailored to Debian based Linux distros and has been tested on Proxmox 8.4 and Ubuntu 25.04. +The unit file has been tailored to Debian-based Linux distros and has been tested on Proxmox 8.4 and Ubuntu 25.04. Requirements: - `/dev/ttyACM0`: `dialout` group with rw permissions. - To run as root: remove `DynamicUser` and `Group` settings. - -## Install +### Install As root user, otherwise `sudo` is required: ```shell -cp asterctl /usr/bin/ +cp asterctl /usr/local/bin/ cp lcd-off.service /etc/systemd/system/ systemctl daemon-reload systemctl enable lcd-off ``` -## Security +### Security The systemd unit file uses strong security settings to only allow operations required for `asterctl`: @@ -120,3 +121,24 @@ systemd-analyze security lcd-off.service ``` → Overall exposure level for lcd-off.service: 0.8 SAFE 😀 ``` + +## asterctl Daemon + +_TODO_ + +## aster-sysinfo Daemon + +‼️ Work in progress. This also requires the `asterctl` daemon running. + +The systemd unit [aster-sysinfo.service](https://github.com/zehnm/aoostar-rs/blob/main/linux/aster-sysinfo.service) +can be installed to automatically collect system sensor information for `asterctl`. + +### Install + +As root user, otherwise `sudo` is required: +```shell +cp aster-sysinfo /usr/local/bin/ +cp aster-sysinfo.service /etc/systemd/system/ +systemctl daemon-reload +systemctl enable aster-sysinfo +``` diff --git a/docs/sensor/README.md b/docs/sensor/README.md index 89077f3..d89fa05 100644 --- a/docs/sensor/README.md +++ b/docs/sensor/README.md @@ -25,4 +25,4 @@ Only the file data source is supported at the moment, other sources like pipes, ### Sensor Data Providers - Proof of concept [Linux shell scripts](provider/shell_scripts.md) -- [sysinfo tool](provider/sysinfo.md) +- [aster-sysinfo tool](provider/sysinfo.md) diff --git a/docs/sensor/provider/sysinfo.md b/docs/sensor/provider/sysinfo.md index 3993120..979d2fd 100644 --- a/docs/sensor/provider/sysinfo.md +++ b/docs/sensor/provider/sysinfo.md @@ -1,6 +1,6 @@ -# sysinfo Tool +# aster-sysinfo Tool -The Rust based [sysinfo](https://github.com/zehnm/aoostar-rs/blob/main/crates/sysinfo) tool gathers many more system sensor values with the help of +The Rust based [aster-sysinfo](https://github.com/zehnm/aoostar-rs/blob/main/crates/sysinfo) tool gathers many more system sensor values with the help of the [sysinfo](https://github.com/GuillaumeGomez/sysinfo) crate. It supports FreeBSD, Linux, macOS, Windows and other OSes, but it has only been tested on Linux so far. @@ -8,7 +8,7 @@ It supports FreeBSD, Linux, macOS, Windows and other OSes, but it has only been ``` Proof of concept sensor value collection for the asterctl screen control tool -Usage: sysinfo [OPTIONS] +Usage: aster-sysinfo [OPTIONS] Options: -o, --out @@ -39,13 +39,13 @@ Options: Single test run with printing all sensors in the console: ```shell -sysinfo --console +aster-sysinfo --console ``` Normal mode providing sensor values for `asterctl` in `/tmp/sensors/sysinfo.txt` every 3 seconds: ```shell -sysinfo --refresh 3 --out /tmp/sensors/sysinfo.txt +aster-sysinfo --refresh 3 --out /tmp/sensors/aster-sysinfo.txt ``` Note: the lower the refresh rate, the more resources are used! diff --git a/linux/aster-sysinfo.service b/linux/aster-sysinfo.service new file mode 100644 index 0000000..a8f9996 --- /dev/null +++ b/linux/aster-sysinfo.service @@ -0,0 +1,44 @@ +[Unit] +Description=Daemon for gathering sensor values for asterctl +After=local-fs.target + +[Service] +Type=exec +DynamicUser=true + +# Use /run/asterctl directory for writing sensor file +RuntimeDirectory=asterctl +#Logging configuration +#Environment=RUST_LOG=debug +ExecStart=/usr/local/bin/aster-sysinfo --out /run/asterctl/sensors/sysinfo.txt --temp-dir /run/asterctl --refresh 3 +# Created files are world-readable +UMask=002 + +# Lock down service, remove single entries or whole section if metrics gathering doesn't work +# START lock down +CapabilityBoundingSet= +LockPersonality=true +RestrictNamespaces=true +ProtectHome=true +ProtectSystem=strict +NoNewPrivileges=true +ProtectKernelTunables=true +ProtectKernelModules=true +ProtectKernelLogs=true +ProtectControlGroups=true +MemoryDenyWriteExecute=true +RestrictSUIDSGID=true +KeyringMode=private +ProtectClock=true +RestrictRealtime=true +PrivateTmp=true +PrivateUsers=true +ProtectHostname=true +RestrictAddressFamilies=none +SystemCallFilter=@system-service +SystemCallFilter=~@privileged @resources +SystemCallErrorNumber=EPERM +# END lock down + +[Install] +WantedBy=multi-user.target