mirror of
https://codeberg.org/icewind/netnsd.git
synced 2026-06-04 01:24:07 +02:00
don't remove namespaces on daemon exit
This commit is contained in:
parent
9af09c8669
commit
3a8b684600
6 changed files with 52 additions and 56 deletions
|
|
@ -1,20 +1,20 @@
|
|||
use crate::config::{Config, ForwardConfig, NamespaceConfig, NamespaceName};
|
||||
use crate::namespace::{NamespaceError, NetNs};
|
||||
use crate::proxy::{ActiveProxy, ProxyError};
|
||||
use futures::FutureExt;
|
||||
use futures::StreamExt;
|
||||
use futures_concurrency::stream::Merge;
|
||||
use humansize::{BINARY, SizeFormatter};
|
||||
use main_error::MainResult;
|
||||
use sd_notify::{NotifyState, notify};
|
||||
use std::io::Error as IoError;
|
||||
use std::pin::pin;
|
||||
use humansize::{SizeFormatter, BINARY};
|
||||
use thiserror::Error;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::signal::ctrl_c;
|
||||
use tokio::signal::unix::{SignalKind, signal};
|
||||
use tokio_stream::wrappers::SignalStream;
|
||||
use tracing::{debug, error, info};
|
||||
use crate::proxy::{ActiveProxy, ProxyError};
|
||||
|
||||
pub fn daemon(config: Config) -> MainResult {
|
||||
let rt = Runtime::new()?;
|
||||
|
|
@ -91,7 +91,7 @@ async fn daemon_async(mut config: Config) -> Result<(), DaemonError> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let _ = notify(false, &[NotifyState::Stopping]);
|
||||
|
||||
Ok(())
|
||||
|
|
@ -111,20 +111,11 @@ struct State {
|
|||
|
||||
impl State {
|
||||
pub fn update(&mut self, config: &Config) -> Result<(), DaemonError> {
|
||||
self.namespaces.retain_mut(|existing| {
|
||||
if let Some(new_config) =
|
||||
config
|
||||
.namespaces
|
||||
.iter()
|
||||
.find(|new| &new.name == existing.name()) {
|
||||
if let Err(error) = existing.update_proxies(new_config) {
|
||||
error!(%error, "Failed to update proxies for namespace");
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
});
|
||||
for removed in self.namespaces.extract_if(.., |namespace| {
|
||||
config.get_namespace(namespace.name()).is_none()
|
||||
}) {
|
||||
removed.ns.delete()?;
|
||||
}
|
||||
|
||||
for new in &config.namespaces {
|
||||
if !self.has_namespace(&new.name) {
|
||||
|
|
@ -132,6 +123,11 @@ impl State {
|
|||
}
|
||||
}
|
||||
|
||||
for namespace in &mut self.namespaces {
|
||||
let config = config.get_namespace(namespace.name()).unwrap();
|
||||
namespace.update_proxies(config)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -161,7 +157,8 @@ impl ActiveNamespace {
|
|||
}
|
||||
|
||||
pub fn update_proxies(&mut self, config: &NamespaceConfig) -> Result<(), DaemonError> {
|
||||
self.proxies.retain(|existing| config.forward.iter().any(|new| existing == new));
|
||||
self.proxies
|
||||
.retain(|existing| config.forward.iter().any(|new| existing == new));
|
||||
|
||||
for new in &config.forward {
|
||||
if !self.has_forward(new) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue