Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit 8e8a7dc

Browse files
committed
...
1 parent 3b19d5b commit 8e8a7dc

File tree

5 files changed

+53
-71
lines changed

5 files changed

+53
-71
lines changed

install.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ YELLOW='\033[0;33m'
88
NC='\033[0m' # No Color
99

1010
echo -e "${GREEN}stop zinit...${NC}"
11-
curl -fsSL https://raw.githubusercontent.com/threefoldtech/zinit/refs/heads/master/stop.sh | bash
11+
rm -f /tmp/stop.sh
12+
curl -fsSL https://raw.githubusercontent.com/threefoldtech/zinit/refs/heads/master/stop.sh > /tmp/stop.sh
13+
bash /tmp/stop.sh
1214

1315

1416
# GitHub repository information

install_run.sh

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,29 @@ GREEN='\033[0;32m'
77
YELLOW='\033[0;33m'
88
NC='\033[0m' # No Color
99

10+
# Function to check if zinit is running
11+
is_zinit_running() {
12+
if zinit list &>/dev/null; then
13+
return 0 # Command successful, zinit is running
14+
else
15+
return 1 # Command failed, zinit is not running
16+
fi
17+
}
18+
1019
echo -e "${GREEN}Starting zinit installation and setup...${NC}"
1120
# Download and execute install.sh
1221
echo -e "${YELLOW}Downloading and executing install.sh...${NC}"
1322
curl -fsSL https://raw.githubusercontent.com/threefoldtech/zinit/refs/heads/master/install.sh | bash
1423

15-
# Determine the path to zinit based on OS
16-
if [ "$(uname -s)" = "Darwin" ]; then
17-
ZINIT_PATH="$HOME/hero/bin/zinit"
18-
else
19-
if [ "$(id -u)" -eq 0 ]; then
20-
ZINIT_PATH="/usr/local/bin/zinit"
21-
else
22-
ZINIT_PATH="$HOME/.local/bin/zinit"
23-
fi
24-
fi
25-
26-
# Ensure zinit is in PATH
27-
export PATH="$PATH:$(dirname "$ZINIT_PATH")"
24+
echo -e "${GREEN}install zinit...${NC}"
25+
rm -f /tmp/install.sh
26+
curl -fsSL https://raw.githubusercontent.com/threefoldtech/zinit/refs/heads/master/install.sh > /tmp/install.sh
27+
bash /tmp/install.sh
2828

29-
# Function to check if zinit is running
30-
is_zinit_running() {
31-
pgrep -f "zinit$" > /dev/null
32-
return $?
33-
}
34-
35-
# Try to shutdown zinit gracefully if it's running
36-
if is_zinit_running; then
37-
echo -e "${YELLOW}Zinit is already running. Attempting graceful shutdown...${NC}"
38-
"$ZINIT_PATH" shutdown || true
39-
40-
# Give it a moment to shut down
41-
sleep 2
42-
43-
# Check if it's still running
44-
if is_zinit_running; then
45-
echo -e "${YELLOW}Zinit is still running. Attempting to kill the process...${NC}"
46-
pkill -f "zinit$" || true
47-
sleep 1
48-
fi
49-
else
50-
echo -e "${YELLOW}No existing zinit process found.${NC}"
51-
fi
52-
53-
# Double-check no zinit is running
54-
if is_zinit_running; then
55-
echo -e "${RED}Warning: Could not terminate existing zinit process. You may need to manually kill it.${NC}"
56-
ps aux | grep "zinit" | grep -v grep
57-
else
58-
echo -e "${GREEN}No zinit process is running. Ready to start a new instance.${NC}"
59-
fi
6029

6130
# Launch zinit in the background
6231
echo -e "${GREEN}Starting zinit in the background...${NC}"
63-
"$ZINIT_PATH" &
32+
zinit &
6433

6534
# Give it a moment to start
6635
sleep 1

openrpc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"methods": [
1818
{
19-
"name": "rpc_discover",
19+
"name": "rpc.discover",
2020
"description": "Returns the OpenRPC specification for the API",
2121
"params": [],
2222
"result": {

src/app/rpc.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ const OPENRPC_SPEC: &str = include_str!("../../openrpc.json");
2525
/// RPC methods for discovery.
2626
#[rpc(server, client)]
2727
pub trait ZinitRpcApi {
28-
/// Returns the OpenRPC specification as a JSON Value.
28+
/// Returns the OpenRPC specification as a string.
2929
#[method(name = "rpc.discover")]
30-
async fn discover(&self) -> RpcResult<Value>;
30+
async fn discover(&self) -> RpcResult<String>;
3131
}
3232

3333
#[async_trait]
3434
impl ZinitRpcApiServer for Api {
35-
async fn discover(&self) -> RpcResult<Value> {
36-
let spec = serde_json::from_str(OPENRPC_SPEC).expect("Failed to parse OpenRPC spec");
37-
Ok(spec)
35+
async fn discover(&self) -> RpcResult<String> {
36+
Ok(OPENRPC_SPEC.to_string())
3837
}
3938
}
4039

src/zinit/lifecycle.rs

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -326,29 +326,35 @@ impl LifecycleManager {
326326

327327
/// Get memory and CPU usage for a process
328328
async fn get_process_stats(&self, pid: i32) -> Result<(u64, f32)> {
329-
// Create a new System instance
330-
let mut system = System::new();
331-
329+
// Create a new System instance with all information
330+
let mut system = System::new_all();
331+
332332
// Convert i32 pid to sysinfo::Pid
333333
let sys_pid = sysinfo::Pid::from(pid as usize);
334-
334+
335+
// Make sure we're refreshing CPU information
336+
system.refresh_cpu();
337+
system.refresh_processes();
338+
335339
// First refresh to get initial CPU values
336-
system.refresh_process(sys_pid);
337-
338-
// Wait a short time for CPU measurement
339-
sleep(std::time::Duration::from_millis(100)).await;
340-
340+
system.refresh_all();
341+
342+
// Wait longer for CPU measurement (500ms instead of 100ms)
343+
sleep(std::time::Duration::from_millis(500)).await;
344+
341345
// Refresh again to get updated CPU values
342-
system.refresh_process(sys_pid);
343-
346+
system.refresh_cpu();
347+
system.refresh_processes();
348+
system.refresh_all();
349+
344350
// Get the process
345351
if let Some(process) = system.process(sys_pid) {
346352
// Get memory in bytes
347353
let memory_usage = process.memory();
348-
354+
349355
// Get CPU usage as percentage
350356
let cpu_usage = process.cpu_usage();
351-
357+
352358
Ok((memory_usage, cpu_usage))
353359
} else {
354360
// Process not found
@@ -360,16 +366,22 @@ impl LifecycleManager {
360366
async fn get_child_process_stats(&self, parent_pid: i32) -> Result<Vec<ProcessStats>> {
361367
// Create a new System instance with all processes information
362368
let mut system = System::new_all();
369+
370+
// Make sure we're refreshing CPU information
371+
system.refresh_cpu();
372+
system.refresh_processes();
363373
system.refresh_all();
364-
374+
365375
// Convert i32 pid to sysinfo::Pid
366376
let sys_pid = sysinfo::Pid::from(parent_pid as usize);
367-
368-
// Wait a short time for CPU measurement
369-
sleep(std::time::Duration::from_millis(100)).await;
370-
371-
// Refresh processes to get updated CPU values
377+
378+
// Wait longer for CPU measurement (500ms instead of 100ms)
379+
sleep(std::time::Duration::from_millis(500)).await;
380+
381+
// Refresh all system information to get updated CPU values
382+
system.refresh_cpu();
372383
system.refresh_processes();
384+
system.refresh_all();
373385

374386
let mut children = Vec::new();
375387

0 commit comments

Comments
 (0)