diff --git a/radicle-node/src/control.rs b/radicle-node/src/control.rs index 0c5b09b5..819509ce 100644 --- a/radicle-node/src/control.rs +++ b/radicle-node/src/control.rs @@ -4,7 +4,7 @@ use std::io::BufReader; use std::io::LineWriter; use std::os::unix::net::UnixListener; use std::os::unix::net::UnixStream; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::{fs, io, net}; use crate::client; @@ -17,12 +17,22 @@ use crate::service::FetchResult; pub enum Error { #[error("failed to bind control socket listener: {0}")] Bind(io::Error), + #[error("invalid socket path specified: {0}")] + InvalidPath(PathBuf), } /// Listen for commands on the control socket, and process them. pub fn listen, H: Handle>(path: P, handle: H) -> Result<(), Error> { // Remove the socket file on startup before rebinding. fs::remove_file(&path).ok(); + fs::create_dir_all( + path.as_ref() + .parent() + .ok_or_else(|| Error::InvalidPath(path.as_ref().to_path_buf()))?, + ) + .ok(); + + log::info!("Binding control socket {}..", path.as_ref().display()); let listener = UnixListener::bind(path).map_err(Error::Bind)?; for incoming in listener.incoming() { diff --git a/radicle-node/src/main.rs b/radicle-node/src/main.rs index e1bac11d..838941e0 100644 --- a/radicle-node/src/main.rs +++ b/radicle-node/src/main.rs @@ -1,7 +1,9 @@ use std::thread; -use std::{env, net, process}; +use std::{net, process}; -use radicle_node::node; +use anyhow::Context as _; + +use radicle_node::logger; use radicle_node::prelude::Address; use radicle_node::{client, control, git, service}; @@ -53,9 +55,12 @@ impl Options { } fn main() -> anyhow::Result<()> { + logger::init(log::Level::Debug)?; + let options = Options::from_env()?; - let profile = radicle::Profile::load()?; - let client = client::Client::::new(profile)?; + let profile = radicle::Profile::load().context("Failed to load node profile")?; + let socket = profile.socket(); + let client = client::Client::::new(profile).context("Failed to initialize client")?; let handle = client.handle(); let config = client::Config { service: service::Config { @@ -65,7 +70,6 @@ fn main() -> anyhow::Result<()> { }, listen: options.listen, }; - let socket = env::var("RAD_SOCKET").unwrap_or_else(|_| node::DEFAULT_SOCKET_NAME.to_owned()); let t1 = thread::spawn(move || control::listen(socket, handle)); let t2 = thread::spawn(move || client.run(config)); diff --git a/radicle/src/profile.rs b/radicle/src/profile.rs index 24944984..55d2f154 100644 --- a/radicle/src/profile.rs +++ b/radicle/src/profile.rs @@ -84,7 +84,7 @@ impl Profile { } /// Get the path to the radicle node socket. - fn socket(&self) -> PathBuf { + pub fn socket(&self) -> PathBuf { env::var_os("RAD_SOCKET") .map(PathBuf::from) .unwrap_or_else(|| self.home.join("node").join(node::DEFAULT_SOCKET_NAME))