feat(owlry-core): add daemon binary entry point
Add [[bin]] target and main.rs that starts the IPC server with env_logger, socket path from XDG_RUNTIME_DIR, and graceful shutdown via ctrlc signal handler. Also add socket_path() to paths module.
This commit is contained in:
@@ -11,6 +11,10 @@ description = "Core daemon for the Owlry application launcher"
|
||||
name = "owlry_core"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "owlry-core"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
owlry-plugin-api = { path = "../owlry-plugin-api" }
|
||||
|
||||
@@ -32,6 +36,9 @@ dirs = "5"
|
||||
# Error handling
|
||||
thiserror = "2"
|
||||
|
||||
# Signal handling
|
||||
ctrlc = { version = "3", features = ["termination"] }
|
||||
|
||||
# Logging & notifications
|
||||
log = "0.4"
|
||||
env_logger = "0.11"
|
||||
|
||||
38
crates/owlry-core/src/main.rs
Normal file
38
crates/owlry-core/src/main.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use log::info;
|
||||
|
||||
use owlry_core::paths;
|
||||
use owlry_core::server::Server;
|
||||
|
||||
fn main() {
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init();
|
||||
|
||||
let sock = paths::socket_path();
|
||||
info!("Starting owlry-core daemon...");
|
||||
|
||||
// Ensure the socket parent directory exists
|
||||
if let Err(e) = paths::ensure_parent_dir(&sock) {
|
||||
eprintln!("Failed to create socket directory: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let server = match Server::bind(&sock) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to start owlry-core: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
// Graceful shutdown on SIGTERM/SIGINT
|
||||
let sock_cleanup = sock.clone();
|
||||
ctrlc::set_handler(move || {
|
||||
let _ = std::fs::remove_file(&sock_cleanup);
|
||||
std::process::exit(0);
|
||||
})
|
||||
.ok();
|
||||
|
||||
if let Err(e) = server.run() {
|
||||
eprintln!("Server error: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,20 @@ pub fn system_data_dirs() -> Vec<PathBuf> {
|
||||
dirs
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Runtime files
|
||||
// =============================================================================
|
||||
|
||||
/// IPC socket path: `$XDG_RUNTIME_DIR/owlry/owlry.sock`
|
||||
///
|
||||
/// Falls back to `/tmp` if `$XDG_RUNTIME_DIR` is not set.
|
||||
pub fn socket_path() -> PathBuf {
|
||||
let runtime_dir = std::env::var("XDG_RUNTIME_DIR")
|
||||
.map(PathBuf::from)
|
||||
.unwrap_or_else(|_| PathBuf::from("/tmp"));
|
||||
runtime_dir.join(APP_NAME).join("owlry.sock")
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Helper functions
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user