refactor: Turn server in a proper command

Turn `server` into proper command, with a `command` function in its own module, its own
error type, etc, in preparation of adding subcommands to it.
pull/24376/head
Marko Mikulicic 2021-03-10 01:03:41 +01:00 committed by kodiakhq[bot]
parent b8942dce0d
commit d1a8872de6
2 changed files with 19 additions and 6 deletions

View File

@ -1,9 +1,12 @@
//! Implementation of command line option for manipulating and showing server
//! config
use crate::commands::logging::LoggingLevel;
use crate::influxdb_ioxd;
use clap::arg_enum;
use std::{net::SocketAddr, net::ToSocketAddrs, path::PathBuf};
use structopt::StructOpt;
use thiserror::Error;
/// The default bind address for the HTTP API.
pub const DEFAULT_API_BIND_ADDR: &str = "127.0.0.1:8080";
@ -15,6 +18,14 @@ pub const DEFAULT_GRPC_BIND_ADDR: &str = "127.0.0.1:8082";
/// specified.
pub const FALLBACK_AWS_REGION: &str = "us-east-1";
#[derive(Debug, Error)]
pub enum Error {
#[error("Server error")]
ServerError(#[from] influxdb_ioxd::Error),
}
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, StructOpt)]
#[structopt(
name = "server",
@ -214,6 +225,10 @@ Possible values (case insensitive):
pub jaeger_host: Option<String>,
}
pub async fn command(logging_level: LoggingLevel, config: Box<Config>) -> Result<()> {
Ok(influxdb_ioxd::main(logging_level, config).await?)
}
fn parse_socket_addr(s: &str) -> std::io::Result<SocketAddr> {
let mut addrs = s.to_socket_addrs()?;
// when name resolution fails, to_socket_address returns a validation error

View File

@ -12,7 +12,7 @@ use std::str::FromStr;
use dotenv::dotenv;
use structopt::StructOpt;
use tokio::runtime::Runtime;
use tracing::{debug, error, warn};
use tracing::{debug, warn};
use commands::logging::LoggingLevel;
use ingest::parquet::writer::CompressionLevel;
@ -187,11 +187,9 @@ fn main() -> Result<(), std::io::Error> {
Some(Command::Server(config)) => {
// Note don't set up basic logging here, different logging rules apply in server
// mode
let res = influxdb_ioxd::main(logging_level, config).await;
if let Err(e) = res {
error!("Server shutdown with error: {}", e);
std::process::exit(ReturnCode::Failure as _);
if let Err(e) = commands::server::command(logging_level, config).await {
eprintln!("Server command failed: {}", e);
std::process::exit(ReturnCode::Failure as _)
}
}
None => {