summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-11-20 11:25:50 +0100
committermetamuffin <metamuffin@disroot.org>2023-11-20 11:25:50 +0100
commitbcc135761db881fd937767788a0d0480bb1b1f31 (patch)
tree90d2ba4ad48ae6ea4c3a545753696a6414fe891c /src/config.rs
parentcd8dca8cd323347a96a6f9c31e7465377e6230d3 (diff)
downloadgnix-bcc135761db881fd937767788a0d0480bb1b1f31.tar
gnix-bcc135761db881fd937767788a0d0480bb1b1f31.tar.bz2
gnix-bcc135761db881fd937767788a0d0480bb1b1f31.tar.zst
fix file watch path
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs
index be41420..9e7f720 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -12,12 +12,14 @@ use std::{
fs::read_to_string,
marker::PhantomData,
net::SocketAddr,
- path::PathBuf,
+ path::{Path, PathBuf},
sync::Arc,
};
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
+ #[serde(default = "true_default")]
+ pub watch_config: bool,
pub http: Option<HttpConfig>,
pub https: Option<HttpsConfig>,
#[serde(default)]
@@ -26,6 +28,10 @@ pub struct Config {
pub hosts: HashMap<String, Route>,
}
+fn true_default() -> bool {
+ true
+}
+
#[derive(Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct Limits {
@@ -157,7 +163,8 @@ where
}
impl Config {
- pub fn load(path: &str) -> anyhow::Result<Config> {
+ pub fn load(path: &Path) -> anyhow::Result<Config> {
+ info!("loading config from {path:?}");
let raw = read_to_string(path).context("reading config file")?;
let config: Config = serde_yaml::from_str(&raw).context("parsing config")?;
Ok(config)
@@ -173,13 +180,13 @@ impl Default for Limits {
}
}
-pub fn setup_file_watch(config_path: String, state: Arc<State>) {
+pub fn setup_file_watch(config_path: PathBuf, state: Arc<State>) {
std::thread::spawn(move || {
let mut inotify = Inotify::init().unwrap();
inotify
.watches()
.add(
- ".",
+ config_path.parent().unwrap(),
WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE,
)
.unwrap();
@@ -191,7 +198,6 @@ pub fn setup_file_watch(config_path: String, state: Arc<State>) {
for event in events {
if event.mask.contains(EventMask::MODIFY) {
- info!("reloading config");
match Config::load(&config_path) {
Ok(conf) => {
let mut r = state.config.blocking_write();