Get the node running
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
961c18319f
commit
706fbc6550
|
|
@ -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<P: AsRef<Path>, 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() {
|
||||
|
|
|
|||
|
|
@ -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::<Reactor>::new(profile)?;
|
||||
let profile = radicle::Profile::load().context("Failed to load node profile")?;
|
||||
let socket = profile.socket();
|
||||
let client = client::Client::<Reactor>::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));
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in New Issue