Added autounmount on stop. Added prom metrics to server 9090 /metrics

This commit is contained in:
2026-03-10 15:52:16 +00:00
parent a5da1c3a34
commit 9534eceb02
8 changed files with 439 additions and 19 deletions

View File

@@ -1,8 +1,10 @@
pub mod fs;
use clap::Parser;
use fuser::MountOption;
use fuser::{MountOption, Session};
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use furumi_client_core::FurumiClient;
#[derive(Parser, Debug)]
@@ -40,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
FurumiClient::connect(&args.server, &args.token).await
})?;
let fs = fs::FurumiFuse::new(client, rt.handle().clone());
let fuse_fs = fs::FurumiFuse::new(client, rt.handle().clone());
let options = vec![
MountOption::RO,
@@ -49,7 +51,30 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
];
println!("Mounting Furumi-ng to {:?}", args.mount);
fuser::mount2(fs, args.mount, &options)?;
// Use Session + BackgroundSession for graceful unmount on exit
let session = Session::new(fuse_fs, &args.mount, &options)?;
// Spawn the FUSE event loop in a background thread.
// When `bg_session` is dropped, the filesystem is automatically unmounted.
let bg_session = session.spawn()?;
// Set up signal handler for graceful shutdown
let running = Arc::new(AtomicBool::new(true));
let r = running.clone();
ctrlc::set_handler(move || {
eprintln!("\nReceived signal, unmounting...");
r.store(false, Ordering::SeqCst);
})?;
// Wait for shutdown signal
while running.load(Ordering::SeqCst) {
std::thread::sleep(std::time::Duration::from_millis(100));
}
// Dropping bg_session automatically unmounts the filesystem
drop(bg_session);
println!("Unmounted successfully.");
Ok(())
}