feat: Migrate SAL to Cargo workspace
- Migrate individual modules to independent crates - Refactor dependencies for improved modularity - Update build system and testing infrastructure - Update documentation to reflect new structure
This commit is contained in:
@@ -94,4 +94,4 @@ pub struct ResourceUsage {
|
||||
pub block_output: String,
|
||||
/// PIDs
|
||||
pub pids: String,
|
||||
}
|
||||
}
|
||||
|
@@ -13,28 +13,28 @@ impl HealthCheck {
|
||||
start_period: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Set the interval between health checks
|
||||
pub fn with_interval(mut self, interval: &str) -> Self {
|
||||
self.interval = Some(interval.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
/// Set the timeout for health checks
|
||||
pub fn with_timeout(mut self, timeout: &str) -> Self {
|
||||
self.timeout = Some(timeout.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
/// Set the number of retries for health checks
|
||||
pub fn with_retries(mut self, retries: u32) -> Self {
|
||||
self.retries = Some(retries);
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
/// Set the start period for health checks
|
||||
pub fn with_start_period(mut self, start_period: &str) -> Self {
|
||||
self.start_period = Some(start_period.to_string());
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,27 +1,27 @@
|
||||
// File: /root/code/git.threefold.info/herocode/sal/src/virt/nerdctl/health_check_script.rs
|
||||
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::path::Path;
|
||||
|
||||
/// Handles health check scripts for containers
|
||||
///
|
||||
///
|
||||
/// This module provides functionality to create and manage health check scripts
|
||||
/// for containers, allowing for more complex health checks than simple commands.
|
||||
|
||||
/// Converts a health check command or script to a usable command
|
||||
///
|
||||
///
|
||||
/// If the input is a single-line command, it is returned as is.
|
||||
/// If the input is a multi-line script, it is written to a file in the
|
||||
/// /root/hero/var/containers directory and the path to that file is returned.
|
||||
///
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
///
|
||||
/// * `cmd` - The command or script to convert
|
||||
/// * `container_name` - The name of the container, used to create a unique script name
|
||||
///
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
///
|
||||
/// * `String` - The command to use for the health check
|
||||
pub fn prepare_health_check_command(cmd: &str, container_name: &str) -> String {
|
||||
// If the command is a multiline script, write it to a file
|
||||
@@ -32,16 +32,16 @@ pub fn prepare_health_check_command(cmd: &str, container_name: &str) -> String {
|
||||
// If we can't create the directory, just use the command as is
|
||||
return cmd.to_string();
|
||||
}
|
||||
|
||||
|
||||
// Create a unique filename based on container name
|
||||
let script_path = format!("{}/healthcheck_{}.sh", dir_path, container_name);
|
||||
|
||||
|
||||
// Write the script to the file
|
||||
if let Err(_) = fs::write(&script_path, cmd) {
|
||||
// If we can't write the file, just use the command as is
|
||||
return cmd.to_string();
|
||||
}
|
||||
|
||||
|
||||
// Make the script executable
|
||||
if let Ok(metadata) = fs::metadata(&script_path) {
|
||||
let mut perms = metadata.permissions();
|
||||
@@ -54,7 +54,7 @@ pub fn prepare_health_check_command(cmd: &str, container_name: &str) -> String {
|
||||
// If we can't get metadata, just use the script path with sh
|
||||
return format!("sh {}", script_path);
|
||||
}
|
||||
|
||||
|
||||
// Use the script path as the command
|
||||
script_path
|
||||
} else {
|
||||
@@ -64,16 +64,16 @@ pub fn prepare_health_check_command(cmd: &str, container_name: &str) -> String {
|
||||
}
|
||||
|
||||
/// Cleans up health check scripts for a container
|
||||
///
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
///
|
||||
/// * `container_name` - The name of the container whose health check scripts should be cleaned up
|
||||
pub fn cleanup_health_check_scripts(container_name: &str) {
|
||||
let dir_path = "/root/hero/var/containers";
|
||||
let script_path = format!("{}/healthcheck_{}.sh", dir_path, container_name);
|
||||
|
||||
|
||||
// Try to remove the script file if it exists
|
||||
if Path::new(&script_path).exists() {
|
||||
let _ = fs::remove_file(script_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +1,17 @@
|
||||
mod images;
|
||||
mod cmd;
|
||||
mod container_types;
|
||||
mod container;
|
||||
mod container_builder;
|
||||
mod health_check;
|
||||
mod health_check_script;
|
||||
mod container_operations;
|
||||
mod container_functions;
|
||||
mod container_operations;
|
||||
#[cfg(test)]
|
||||
mod container_test;
|
||||
mod container_types;
|
||||
mod health_check;
|
||||
mod health_check_script;
|
||||
mod images;
|
||||
|
||||
use std::fmt;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
|
||||
/// Error type for nerdctl operations
|
||||
@@ -32,7 +32,9 @@ pub enum NerdctlError {
|
||||
impl fmt::Display for NerdctlError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
NerdctlError::CommandExecutionFailed(e) => write!(f, "Failed to execute nerdctl command: {}", e),
|
||||
NerdctlError::CommandExecutionFailed(e) => {
|
||||
write!(f, "Failed to execute nerdctl command: {}", e)
|
||||
}
|
||||
NerdctlError::CommandFailed(e) => write!(f, "Nerdctl command failed: {}", e),
|
||||
NerdctlError::JsonParseError(e) => write!(f, "Failed to parse JSON: {}", e),
|
||||
NerdctlError::ConversionError(e) => write!(f, "Conversion error: {}", e),
|
||||
@@ -50,8 +52,8 @@ impl Error for NerdctlError {
|
||||
}
|
||||
}
|
||||
|
||||
pub use images::*;
|
||||
pub use cmd::*;
|
||||
pub use container_types::{Container, HealthCheck, ContainerStatus, ResourceUsage};
|
||||
pub use container_functions::*;
|
||||
pub use health_check_script::*;
|
||||
pub use container_types::{Container, ContainerStatus, HealthCheck, ResourceUsage};
|
||||
pub use health_check_script::*;
|
||||
pub use images::*;
|
||||
|
Reference in New Issue
Block a user