aboutsummaryrefslogtreecommitdiff
path: root/src/garage
diff options
context:
space:
mode:
Diffstat (limited to 'src/garage')
-rw-r--r--src/garage/cli/init.rs8
-rw-r--r--src/garage/main.rs25
2 files changed, 25 insertions, 8 deletions
diff --git a/src/garage/cli/init.rs b/src/garage/cli/init.rs
index 9eda085f..80283c8f 100644
--- a/src/garage/cli/init.rs
+++ b/src/garage/cli/init.rs
@@ -1,5 +1,7 @@
use std::path::PathBuf;
+use log::warn;
+
use garage_util::error::*;
pub const READ_KEY_ERROR: &str = "Unable to read node key. It will be generated by your garage node the first time is it launched. Ensure that your garage node is currently running. (The node key is supposed to be stored in your metadata directory.)";
@@ -22,11 +24,11 @@ pub fn node_id_command(config_file: PathBuf, quiet: bool) -> Result<(), Error> {
println!("{}", idstr);
if !quiet {
- eprintln!("WARNING: I don't know the public address to reach this node.");
- eprintln!("In all of the instructions below, replace 127.0.0.1:3901 by the appropriate address and port.");
+ warn!("WARNING: I don't know the public address to reach this node.");
+ warn!("In all of the instructions below, replace 127.0.0.1:{} by the appropriate address and port.", config.rpc_bind_addr.port());
}
- format!("{}@127.0.0.1:3901", idstr)
+ format!("{}@127.0.0.1:{}", idstr, config.rpc_bind_addr.port())
};
if !quiet {
diff --git a/src/garage/main.rs b/src/garage/main.rs
index 7f7196d9..2a939730 100644
--- a/src/garage/main.rs
+++ b/src/garage/main.rs
@@ -9,6 +9,7 @@ mod cli;
mod repair;
mod server;
+use std::net::SocketAddr;
use std::path::PathBuf;
use structopt::StructOpt;
@@ -46,6 +47,9 @@ struct Opt {
#[tokio::main]
async fn main() {
+ if std::env::var("RUST_LOG").is_err() {
+ std::env::set_var("RUST_LOG", "garage=info")
+ }
pretty_env_logger::init();
sodiumoxide::init().expect("Unable to init sodiumoxide");
@@ -99,12 +103,23 @@ async fn cli_command(opt: Opt) -> Result<(), Error> {
let (id, addr) = if let Some(h) = opt.rpc_host {
let (id, addrs) = parse_and_resolve_peer_addr(&h).ok_or_else(|| format!("Invalid RPC remote node identifier: {}. Expected format is <pubkey>@<IP or hostname>:<port>.", h))?;
(id, addrs[0])
- } else if let Some(a) = config.as_ref().map(|c| c.rpc_public_addr).flatten() {
- let node_id = garage_rpc::system::read_node_id(&config.unwrap().metadata_dir)
- .err_context(READ_KEY_ERROR)?;
- (node_id, a)
} else {
- return Err(Error::Message("No RPC host provided".into()));
+ let node_id = garage_rpc::system::read_node_id(&config.as_ref().unwrap().metadata_dir)
+ .err_context(READ_KEY_ERROR)?;
+ if let Some(a) = config.as_ref().map(|c| c.rpc_public_addr).flatten() {
+ (node_id, a)
+ } else {
+ let default_addr = SocketAddr::new(
+ "127.0.0.1".parse().unwrap(),
+ config.as_ref().unwrap().rpc_bind_addr.port(),
+ );
+ warn!(
+ "Trying to contact Garage node at default address {}",
+ default_addr
+ );
+ warn!("If this doesn't work, consider adding rpc_public_addr in your config file or specifying the -h command line parameter.");
+ (node_id, default_addr)
+ }
};
// Connect to target host