cleanup
This commit is contained in:
@@ -6,7 +6,7 @@ use serde_derive::*;
|
||||
use std::ffi::OsStr;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::{Path, PathBuf};
|
||||
use sysinfo::{DiskExt, System, SystemExt};
|
||||
use sysinfo::{DiskExt, SystemExt};
|
||||
use url::Url;
|
||||
use veilid_core::tools::*;
|
||||
use veilid_core::*;
|
||||
@@ -174,7 +174,7 @@ core:
|
||||
)
|
||||
.replace(
|
||||
"%REMOTE_MAX_SUBKEY_CACHE_MEMORY_MB%",
|
||||
&Settings::get_default_remote_max_subkey_cache_memory_mb().to_string_lossy(),
|
||||
&Settings::get_default_remote_max_subkey_cache_memory_mb().to_string(),
|
||||
);
|
||||
config::Config::builder()
|
||||
.add_source(config::File::from_str(
|
||||
@@ -638,7 +638,7 @@ impl Settings {
|
||||
}
|
||||
|
||||
// Generate config
|
||||
let inner: SettingsInner = cfg.try_deserialize()?;
|
||||
let mut inner: SettingsInner = cfg.try_deserialize()?;
|
||||
|
||||
// Fill in missing defaults
|
||||
if inner.core.network.dht.remote_max_storage_space_mb == 0 {
|
||||
@@ -857,14 +857,13 @@ impl Settings {
|
||||
}
|
||||
|
||||
pub fn get_default_remote_max_subkey_cache_memory_mb() -> usize {
|
||||
let mut sys = System::new_with_specifics(sysinfo::RefreshKind::new().with_memory());
|
||||
let sys = sysinfo::System::new_with_specifics(sysinfo::RefreshKind::new().with_memory());
|
||||
sys.free_memory() as usize / 8
|
||||
}
|
||||
|
||||
pub fn get_default_remote_max_storage_space_mb(inner: &SettingsInner) -> usize {
|
||||
let mut sys = System::new_with_specifics(sysinfo::RefreshKind::new().with_disks());
|
||||
pub fn get_default_remote_max_storage_space_mb(inner: &SettingsInner) -> u32 {
|
||||
let mut sys = sysinfo::System::new_with_specifics(sysinfo::RefreshKind::new().with_disks());
|
||||
let dht_storage_path = inner.core.table_store.directory.clone();
|
||||
let mut available_mb = 0usize;
|
||||
// Sort longer mount point paths first since we want the mount point closest to our table store directory
|
||||
sys.sort_disks_by(|a, b| {
|
||||
b.mount_point()
|
||||
@@ -874,13 +873,13 @@ impl Settings {
|
||||
});
|
||||
for disk in sys.disks() {
|
||||
if dht_storage_path.starts_with(disk.mount_point()) {
|
||||
let available_mb = disk.available_space() / 1_000_000usize;
|
||||
let available_mb = disk.available_space() / 1_000_000u64;
|
||||
if available_mb > 40_000 {
|
||||
// Default to 10GB if more than 40GB is available
|
||||
return 10_000;
|
||||
}
|
||||
// Default to 1/4 of the available space, if less than 40GB is available
|
||||
return available_mb;
|
||||
return available_mb as u32;
|
||||
}
|
||||
}
|
||||
// If we can't figure out our storage path go with 1GB of space and pray
|
||||
|
@@ -7,7 +7,7 @@ use clap::ArgMatches;
|
||||
use futures_util::StreamExt;
|
||||
use signal_hook::consts::signal::*;
|
||||
use signal_hook_async_std::Signals;
|
||||
use std::io::Read;
|
||||
//use std::io::Read;
|
||||
use tracing::*;
|
||||
|
||||
#[instrument(skip(signals))]
|
||||
@@ -34,23 +34,23 @@ pub fn run_daemon(settings: Settings, _matches: ArgMatches) -> EyreResult<()> {
|
||||
let s = settings.read();
|
||||
if let Some(pid_file) = s.daemon.pid_file.clone() {
|
||||
daemon = daemon.pid_file(pid_file.clone()); //.chown_pid_file(true);
|
||||
daemon = daemon.exit_action(move || {
|
||||
// wait for pid file to exist before exiting parent
|
||||
let pid_path = std::path::Path::new(&pid_file);
|
||||
loop {
|
||||
if let Ok(mut f) = std::fs::File::open(pid_path) {
|
||||
let mut s = String::new();
|
||||
if f.read_to_string(&mut s).is_ok()
|
||||
&& !s.is_empty()
|
||||
&& s.parse::<u32>().is_ok()
|
||||
{
|
||||
println!("pidfile found");
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
}
|
||||
})
|
||||
// daemon = daemon.exit_action(move || {
|
||||
// // wait for pid file to exist before exiting parent
|
||||
// let pid_path = std::path::Path::new(&pid_file);
|
||||
// loop {
|
||||
// if let Ok(mut f) = std::fs::File::open(pid_path) {
|
||||
// let mut s = String::new();
|
||||
// if f.read_to_string(&mut s).is_ok()
|
||||
// && !s.is_empty()
|
||||
// && s.parse::<u32>().is_ok()
|
||||
// {
|
||||
// println!("pidfile found");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
// }
|
||||
// })
|
||||
}
|
||||
if let Some(chroot) = &s.daemon.chroot {
|
||||
daemon = daemon.chroot(chroot);
|
||||
|
Reference in New Issue
Block a user