Compare commits

..

No commits in common. "ee64e39c50384a00f642fa263c24036c5c8082e6" and "da276b034f18bde915efa7648ce5bbfec5d29ecb" have entirely different histories.

13 changed files with 45 additions and 120 deletions

2
.gitignore vendored
View File

@ -5,5 +5,3 @@ Cargo.lock
hagent_test.sock hagent_test.sock
release release
*.sock *.sock
*.bak
docker-compose.yml

View File

@ -1,20 +1,10 @@
# noxis # noxis-rs
![Logo](logo.png) ![Logo](logo.png)
### In-container integrating util to handle processes runtime
( with amd64 and riscv64 support )
`noxis` - monitoring util with special attention on ## Depends on
1) **Speed**
2) **Multiplatform** execution *(with `amd64` and `riscv64` **support**)*
3) **Smallness** and **Optimization**
It's **main tasks** are
- to manage the processes that occur inside the container or in the target system.
- collect data (metrics);
- monitor the availability of system files necessary for the operation of processes;
- check whether there is a connection between processes and services, where the information comes from or where it is sent.
## Build requirements
- `rustup (>=1.27.1)` - `rustup (>=1.27.1)`
- `gcc-riscv64-unknown-elf` - `gcc-riscv64-unknown-elf`
- `build-essential` - `build-essential`
@ -22,70 +12,60 @@ It's **main tasks** are
- `binutils-riscv64-linux-gnu` - `binutils-riscv64-linux-gnu`
## Key items in repo ## Setting up
Download and execute rustup.sh
1) Main daemon `noxis-rs` ~~~bash
2) CLI `noxis-cli`
3) Unix-Socket to Web-Socket **Proxy** for integrations `noxis-proxy`
## Setting up device
Download and execute rustup.sh *(for building)*
~~~ bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
~~~ ~~~
## Building ## Building
1. Clone `noxis` 1. Clone this repo `runner-rs`
~~~ bash ~~~bash
git clone https://github.com/prplV/noxis git clone https://github.com/prplV/runner-rs
~~~ ~~~
2. Enter project's dir and set up toolchain list to compile code for RISC-V or x86_64 2. Enter project's dir and set up toolchain list to compile code for RISC-V and AMD64
~~~ bash ~~~bash
cd noxis/ && rustup target add riscv64gc-unknown-linux-gnu && rustup target add x86_64-unknown-linux-gnu cd runner-rs/ && rustup target add riscv64gc-unknown-linux-gnu && rustup target add x86_64-unknown-linux-gnu
~~~ ~~~
> [!NOTE] > [!NOTE]
> Cargo is configured to build an apputil for x86_64/linux defaultly. RISCV-based compilation is optional. > Cargo is configured to build an app for amd64/linux defaultly. RISCV-based compilation is optional.
3.1. Release build of util for x86_64/linux 3.1. Release build of app for amd64/linux
~~~bash ~~~bash
cargo x86_64 cargo x86_64
~~~ ~~~
3.2. Release build of util for riscv64/linux 3.2. Release build of app for riscv64/linux
~~~bash ~~~bash
cargo riscv64 cargo riscv64
~~~ ~~~
3.3. Release build of util for both (riscv64 and x86_64) 3.3. Release build of app for both (riscv64 and amd64)
~~~bash ~~~bash
cargo unibuild cargo unibuild
~~~ ~~~
## Execution **DAEMON** for x86_64/linux ## Execution for amd64/linux
1) If you work on x86_64/linux machine execute:
~~~bash ~~~bash
./target/x86_64-unknown-linux-gnu/release/noxis-rs ./target/x86_64-unknown-linux-gnu/release/runner-rs
~~~ ~~~
or or
~~~bash ~~~bash
cargo run_x86 cargo run_x86
~~~ ~~~
2) If you work on riscv64/linux machine execute:
## Execution for riscv64/linux
~~~bash ~~~bash
./target/riscv64gc-unknown-linux-gnu/release/noxis-rs ./target/riscv64gc-unknown-linux-gnu/release/runner-rs
~~~ ~~~
or or
> [!CAUTION] > [!CAUTION]

BIN
logo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 KiB

After

Width:  |  Height:  |  Size: 152 KiB

View File

@ -1,4 +0,0 @@
.env
.env.example
README.md
target

View File

@ -1,19 +0,0 @@
FROM rust:latest AS builder
WORKDIR /app
RUN apt update && apt install -y musl-tools
RUN rustup target add x86_64-unknown-linux-musl
COPY . .
RUN cargo build --release --target=x86_64-unknown-linux-musl
FROM alpine:latest
WORKDIR /app
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/noxis-proxy /app/noxis-proxy
RUN apk add --no-cache ca-certificates
EXPOSE 7654
ENTRYPOINT ["/app/noxis-proxy"]

View File

@ -1,20 +0,0 @@
services:
noxis-proxy:
container_name: noxis-proxy
image: noxis-proxy:0.1.0
networks:
- noxis-net
environment:
- NOXIS_SOCKET_PATH=./noxis.sock
- NOXIS_PROXY_PORT=7654
- NOXIS_LOG_LEVEL=TRACE
volumes:
- /home/user/diplom_code/noxis-rs/noxis.sock:/app/noxis.sock
ports:
- 7654:7654
restart: always
networks:
noxis-net:
driver: bridge

View File

@ -36,7 +36,7 @@ async fn main() -> anyhow::Result<()> {
.route("/hello", get(hello)) .route("/hello", get(hello))
.with_state(app_state); .with_state(app_state);
let bind = format!("0.0.0.0:{}", std::env::var("NOXIS_PROXY_PORT").unwrap_or_else(|_| String::from("7654"))); let bind = format!("0.0.0.0:{}", std::env::var("NOXIS_PROXY_PORT").unwrap_or_else(|_| String::from("3000")));
tracing::info!("Serving on {}", &bind); tracing::info!("Serving on {}", &bind);
@ -61,21 +61,23 @@ async fn hello(
} }
async fn handle_socket(mut ws: WebSocket, state: AppState) { async fn handle_socket(mut ws: WebSocket, state: AppState) {
// Подключаемся к Unix-сокету
tracing::info!("handle websocket"); tracing::info!("handle websocket");
let ws_receiver = tokio::spawn(async move {
while let Some(Ok(msg)) = ws.recv().await {
let mut unix_socket = match UnixStream::connect(&state.socket_path).await { let mut unix_socket = match UnixStream::connect(&state.socket_path).await {
Ok(socket) => socket, Ok(socket) => socket,
Err(e) => { Err(e) => {
tracing::error!("Failed to connect to Unix socket: {}", e); eprintln!("Failed to connect to Unix socket: {}", e);
let _ = ws.send(Message::Text("ERROR: Unix socket connection failed".into())).await; let _ = ws.send(Message::Text("ERROR: Unix socket connection failed".into())).await;
return; return;
} }
}; };
// Отправляем сообщения из WS → Unix
let ws_receiver = tokio::spawn(async move {
while let Some(Ok(msg)) = ws.recv().await {
if let Message::Text(text) = msg { if let Message::Text(text) = msg {
if let Err(e) = unix_socket.write_all(text.as_bytes()).await { if let Err(e) = unix_socket.write_all(text.as_bytes()).await {
tracing::error!("Failed to write to Unix socket: {}", e); eprintln!("Failed to write to Unix socket: {}", e);
break; break;
} }
let mut buf = Vec::new(); let mut buf = Vec::new();
@ -92,5 +94,5 @@ async fn handle_socket(mut ws: WebSocket, state: AppState) {
} }
}); });
let _ = ws_receiver.await; let _ = ws_receiver.await; // Дожидаемся завершения задачи
} }

View File

@ -529,9 +529,9 @@ impl ProcessExtended {
Some(duration) => { Some(duration) => {
format!("{}:{}:{}:{}", format!("{}:{}:{}:{}",
duration.num_days(), duration.num_days(),
duration.num_hours() % 24, duration.num_hours(),
duration.num_minutes() % 60, duration.num_minutes(),
duration.num_seconds() % 60 duration.num_seconds()
) )
}, },
None => String::new() None => String::new()

View File

@ -246,11 +246,7 @@ pub mod v2 {
self.name self.name
); );
if let Err(er) = unfreeze_process(&self.name).await { if let Err(er) = unfreeze_process(&self.name).await {
if er.to_string().contains("already") {
self.state = ProcessState::Pending;
} else {
error!("Cannot unfreeze process {} : {}", self.name, er); error!("Cannot unfreeze process {} : {}", self.name, er);
}
} else { } else {
self.state = ProcessState::Pending; self.state = ProcessState::Pending;
info!("Process {} was unfreezed", &self.name); info!("Process {} was unfreezed", &self.name);
@ -268,14 +264,10 @@ pub mod v2 {
info!("{}: New PID - {}", self.name, self.pid); info!("{}: New PID - {}", self.name, self.pid);
} }
Err(er) => { Err(er) => {
if er.to_string().contains("already") {
self.state = ProcessState::Pending;
} else {
error!("Cannot start process {} : {}", self.name, er); error!("Cannot start process {} : {}", self.name, er);
} }
} }
} }
}
(ProcessState::Pending, (false, false)) => { (ProcessState::Pending, (false, false)) => {
info!( info!(
"{} process was impermissibly stopped. Starting ...", "{} process was impermissibly stopped. Starting ...",

View File

@ -49,7 +49,7 @@ pub mod v2 {
ServicesController { ServicesController {
name: String::new(), name: String::new(),
access_url: Arc::from(String::new()), access_url: Arc::from(String::new()),
state: ServiceState::Ok, state: ServiceState::Unavailable,
config: ConnectionQueue::new(), config: ConnectionQueue::new(),
event_registrator: EventHandlers::new(), event_registrator: EventHandlers::new(),
} }

View File

@ -1,7 +1,5 @@
{ {
"dateOfCreation": "1", "dateOfCreation": "1",
"processes": [] "configServer": "",
}
,
"processes": [] "processes": []
} }

View File

@ -1,7 +1,5 @@
{ {
"dateOfCreation": "1", "dateOfCreation": "1",
"processes": [] "configServer": "",
}
,
"processes": [] "processes": []
} }

View File

@ -1,5 +1,6 @@
{ {
"dateOfCreation": "1721381809103", "dateOfCreation": "1721381809103",
"configServer" : "localhost",
"processes": [ "processes": [
{ {
"name": "temp-process", "name": "temp-process",
@ -11,8 +12,7 @@
"src": "/home/vladislav/web/runner-rs/examples/", "src": "/home/vladislav/web/runner-rs/examples/",
"triggers": { "triggers": {
"onDelete": "hold", "onDelete": "hold",
"onChange": "stop", "onChange": "stop"
"doRestore" : true
} }
} }
], ],