mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-30 23:08:40 +08:00
Changed config file parser at startup, to keep initially dead nodes in list.
This commit is contained in:
@@ -8,6 +8,7 @@ pub mod jwt;
|
|||||||
pub mod kuber;
|
pub mod kuber;
|
||||||
pub mod metrics;
|
pub mod metrics;
|
||||||
pub mod parceyaml;
|
pub mod parceyaml;
|
||||||
|
pub mod state;
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
pub mod tls;
|
pub mod tls;
|
||||||
pub mod tools;
|
pub mod tools;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::utils::healthcheck;
|
use crate::utils::healthcheck;
|
||||||
|
use crate::utils::state::{is_first_run, mark_not_first_run};
|
||||||
use crate::utils::structs::*;
|
use crate::utils::structs::*;
|
||||||
use crate::utils::tools::{clone_dashmap, clone_dashmap_into, print_upstreams};
|
use crate::utils::tools::{clone_dashmap, clone_dashmap_into, print_upstreams};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@@ -139,10 +140,16 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) {
|
|||||||
config.headers.insert(hostname.clone(), header_list);
|
config.headers.insert(hostname.clone(), header_list);
|
||||||
imtdashmap.insert(hostname.clone(), path_map);
|
imtdashmap.insert(hostname.clone(), path_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_first_run() {
|
||||||
|
clone_dashmap_into(&imtdashmap, &config.upstreams);
|
||||||
|
mark_not_first_run();
|
||||||
|
} else {
|
||||||
let y = clone_dashmap(&imtdashmap);
|
let y = clone_dashmap(&imtdashmap);
|
||||||
let r = healthcheck::initiate_upstreams(y).await;
|
let r = healthcheck::initiate_upstreams(y).await;
|
||||||
clone_dashmap_into(&r, &config.upstreams);
|
clone_dashmap_into(&r, &config.upstreams);
|
||||||
println!("Upstream Config:");
|
}
|
||||||
|
info!("Upstream Config:");
|
||||||
print_upstreams(&config.upstreams);
|
print_upstreams(&config.upstreams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
30
src/utils/state.rs
Normal file
30
src/utils/state.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use once_cell::sync::Lazy;
|
||||||
|
use std::sync::RwLock;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SharedState {
|
||||||
|
pub first_run: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub static GLOBAL_STATE: Lazy<RwLock<SharedState>> = Lazy::new(|| RwLock::new(SharedState { first_run: true }));
|
||||||
|
|
||||||
|
pub fn mark_not_first_run() {
|
||||||
|
let mut state = GLOBAL_STATE.write().unwrap();
|
||||||
|
state.first_run = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_first_run() -> bool {
|
||||||
|
let state = GLOBAL_STATE.read().unwrap();
|
||||||
|
state.first_run
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
impl SharedState {
|
||||||
|
pub fn mark_first_run(&mut self) {
|
||||||
|
self.first_run = false;
|
||||||
|
}
|
||||||
|
pub fn is_first_run(&self) -> bool {
|
||||||
|
self.first_run
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -105,14 +105,17 @@ pub fn run() {
|
|||||||
server.add_service(bg_srvc);
|
server.add_service(bg_srvc);
|
||||||
|
|
||||||
thread::spawn(move || server.run_forever());
|
thread::spawn(move || server.run_forever());
|
||||||
drop_priv(cfg.rungroup.clone(), cfg.runuser.clone(), cfg.proxy_address_http.clone(), cfg.proxy_address_tls.clone());
|
|
||||||
|
if let (Some(user), Some(group)) = (cfg.rungroup.clone(), cfg.runuser.clone()) {
|
||||||
|
drop_priv(user, group, cfg.proxy_address_http.clone(), cfg.proxy_address_tls.clone());
|
||||||
|
}
|
||||||
|
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel.")).expect("Error setting Ctrl-C handler");
|
ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel.")).expect("Error setting Ctrl-C handler");
|
||||||
rx.recv().expect("Could not receive from channel.");
|
rx.recv().expect("Could not receive from channel.");
|
||||||
println!("\nSignal received ! Exiting...");
|
info!("Signal received ! Exiting...");
|
||||||
}
|
}
|
||||||
fn drop_priv(user: Option<String>, group: Option<String>, http_addr: String, tls_addr: Option<String>) {
|
fn drop_priv(user: String, group: String, http_addr: String, tls_addr: Option<String>) {
|
||||||
thread::sleep(time::Duration::from_millis(10));
|
thread::sleep(time::Duration::from_millis(10));
|
||||||
loop {
|
loop {
|
||||||
thread::sleep(time::Duration::from_millis(10));
|
thread::sleep(time::Duration::from_millis(10));
|
||||||
@@ -129,12 +132,19 @@ fn drop_priv(user: Option<String>, group: Option<String>, http_addr: String, tls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let (Some(u), Some(g)) = (user, group) {
|
|
||||||
if std::fs::metadata("/proc/self").map(|m| m.uid()).unwrap_or(1) == 0 {
|
if std::fs::metadata("/proc/self").map(|m| m.uid()).unwrap_or(1) == 0 {
|
||||||
info!("Dropping ROOT privileges to: {}:{}", u, g);
|
info!("Dropping ROOT privileges to: {}:{}", user, group);
|
||||||
if let Err(e) = PrivDrop::default().user(u).group(g).apply() {
|
if let Err(e) = PrivDrop::default().user(user).group(group).apply() {
|
||||||
panic!("Failed to drop privileges: {}", e);
|
panic!("Failed to drop privileges: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// if let (Some(u), Some(g)) = (user, group) {
|
||||||
|
// if std::fs::metadata("/proc/self").map(|m| m.uid()).unwrap_or(1) == 0 {
|
||||||
|
// info!("Dropping ROOT privileges to: {}:{}", u, g);
|
||||||
|
// if let Err(e) = PrivDrop::default().user(u).group(g).apply() {
|
||||||
|
// panic!("Failed to drop privileges: {}", e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user