Skip to content

Commit

Permalink
Merge branch 'master' into test/create-password-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams committed Sep 10, 2024
2 parents 406b276 + 8927b0e commit ba1edba
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/bin/cln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ fn make_stack() -> Stack {
// test cln2 updating
auto_update: Some(vec![CLN2.to_string()]),
custom_2b_domain: None,
global_mem_limit: None,
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ pub fn shutdown_now() {

// return a map of name:docker_id
pub async fn build_stack(proj: &str, docker: &Docker, stack: &Stack) -> Result<Clients> {
// set global mem limit if it exists
if let Some(limit) = &stack.global_mem_limit {
use std::sync::atomic::Ordering;
crate::config::GLOBAL_MEM_LIMIT.store(*limit, Ordering::Relaxed);
}
// first create the default network
create_network(docker, None).await?;
// then add the containers
Expand Down
1 change: 1 addition & 0 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub enum SwarmCmd {
GetDockerImageTags(GetDockerImageTagsDetails),
UpdateUser(UpdateUserDetails),
GetApiToken,
SetGlobalMemLimit(u64),
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down
19 changes: 19 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ use rocket::tokio;
use rocket::tokio::sync::Mutex;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::atomic::AtomicU64;

pub static STATE: Lazy<Mutex<State>> = Lazy::new(|| Mutex::new(Default::default()));

pub static GLOBAL_MEM_LIMIT: AtomicU64 = AtomicU64::new(0);

pub struct State {
pub stack: Stack,
pub clients: Clients,
Expand Down Expand Up @@ -64,6 +67,8 @@ pub struct Stack {
pub auto_update: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub custom_2b_domain: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub global_mem_limit: Option<u64>,
}

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -288,6 +293,20 @@ impl Stack {
ip: self.ip.clone(),
auto_update: self.auto_update.clone(),
custom_2b_domain: self.custom_2b_domain.clone(),
global_mem_limit: self.global_mem_limit,
}
}
}

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
struct GbmRes {
global_mem_limit: u64,
}
pub fn set_global_mem_limit(gbm: u64) -> Result<String> {
log::info!("Set Global Memory Limit ===> {:?}", gbm);
use std::sync::atomic::Ordering;
GLOBAL_MEM_LIMIT.store(gbm, Ordering::Relaxed);
Ok(serde_json::to_string(&GbmRes {
global_mem_limit: gbm,
})?)
}
6 changes: 4 additions & 2 deletions src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ impl Default for Stack {
ip: env_no_empty("IP"),
auto_update: None,
custom_2b_domain: env_no_empty("NAV_BOLTWALL_SHARED_HOST"),
global_mem_limit: None,
}
}
}
Expand Down Expand Up @@ -255,9 +256,10 @@ pub fn create_super_user() -> User {
{
Ok(res) => {
if res.status().clone() != 201 {
match res.json::<SendSwarmDetailsResponse>().await {
log::error!("Response code: {:?}", res.status().clone());
match res.text().await {
Ok(data) => {
log::error!("{}", data.message)
log::error!("{:?}", data)
}
Err(err) => {
log::error!("Error parsing JSON response: {:?}", err);
Expand Down
5 changes: 5 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ pub async fn handle(
let response = get_api_token(&boltwall).await?;
return Ok(serde_json::to_string(&response)?);
}
SwarmCmd::SetGlobalMemLimit(gbm) => {
state.stack.global_mem_limit = Some(gbm);
must_save_stack = true;
Some(crate::config::set_global_mem_limit(gbm)?)
}
},
Cmd::Relay(c) => {
let client = state.clients.relay.get(tag).context("no relay client")?;
Expand Down
1 change: 1 addition & 0 deletions src/secondbrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn only_second_brain(network: &str, host: Option<String>, lightning_provider
"navfiber".to_string(),
]),
custom_2b_domain: env_no_empty("NAV_BOLTWALL_SHARED_HOST"),
global_mem_limit: None,
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/sphinxv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub fn sphinxv2_only(network: &str, host: Option<String>) -> Stack {
ip: env_no_empty("IP"),
auto_update: None,
custom_2b_domain: None,
global_mem_limit: None,
}
}

Expand Down Expand Up @@ -109,6 +110,7 @@ pub fn sphinxv1_only(network: &str, host: Option<String>) -> Stack {
ip: env_no_empty("IP"),
auto_update: None,
custom_2b_domain: None,
global_mem_limit: None,
}
}

Expand All @@ -125,5 +127,6 @@ pub fn config_only(host: Option<String>) -> Stack {
ip: env_no_empty("IP"),
auto_update: None,
custom_2b_domain: None,
global_mem_limit: None,
}
}
6 changes: 6 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ pub fn host_config(
};
if let Some(ml) = mem_limit {
hc.memory = Some(ml);
} else {
use std::sync::atomic::Ordering;
let global_mem_limit = crate::config::GLOBAL_MEM_LIMIT.load(Ordering::Relaxed);
if global_mem_limit > 0 {
hc.memory = Some(global_mem_limit as i64);
}
}
Some(hc)
}
Expand Down

0 comments on commit ba1edba

Please sign in to comment.