mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
add launch resume & environment
This commit is contained in:
parent
257b7b4df4
commit
ad83c3ab5a
@ -1,4 +1,3 @@
|
||||
use std::env::VarError::NotPresent;
|
||||
use std::{env, thread};
|
||||
|
||||
use async_std::task;
|
||||
@ -19,20 +18,35 @@ mod analytics;
|
||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
||||
pub fn main() -> Result<(), MainError> {
|
||||
env_logger::init();
|
||||
|
||||
let opt = Opt::from_args();
|
||||
let data = Data::new(opt.clone());
|
||||
|
||||
if env::var("MEILI_NO_ANALYTICS") == Err(NotPresent) {
|
||||
match opt.env.as_ref() {
|
||||
"production" => {
|
||||
if opt.master_key.is_none() {
|
||||
return Err("In production mode, the environment variable MEILI_MASTER_KEY is mandatory".into());
|
||||
}
|
||||
env_logger::init();
|
||||
},
|
||||
"development" => {
|
||||
env_logger::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
if !opt.no_analytics {
|
||||
thread::spawn(analytics::analytics_sender);
|
||||
}
|
||||
|
||||
let data = Data::new(opt.clone());
|
||||
|
||||
let data_cloned = data.clone();
|
||||
data.db.set_update_callback(Box::new(move |name, status| {
|
||||
index_update_callback(name, &data_cloned, status);
|
||||
}));
|
||||
|
||||
print_launch_resume(&opt, &data);
|
||||
|
||||
let mut app = tide::with_state(data);
|
||||
|
||||
app.middleware(Cors::new());
|
||||
@ -40,8 +54,48 @@ pub fn main() -> Result<(), MainError> {
|
||||
|
||||
routes::load_routes(&mut app);
|
||||
|
||||
info!("Server HTTP enabled");
|
||||
|
||||
task::block_on(app.listen(opt.http_addr))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
pub fn print_launch_resume(opt: &Opt, data: &Data) {
|
||||
let ascii_name = r#"
|
||||
888b d888 d8b 888 d8b .d8888b. 888
|
||||
8888b d8888 Y8P 888 Y8P d88P Y88b 888
|
||||
88888b.d88888 888 Y88b. 888
|
||||
888Y88888P888 .d88b. 888 888 888 "Y888b. .d88b. 8888b. 888d888 .d8888b 88888b.
|
||||
888 Y888P 888 d8P Y8b 888 888 888 "Y88b. d8P Y8b "88b 888P" d88P" 888 "88b
|
||||
888 Y8P 888 88888888 888 888 888 "888 88888888 .d888888 888 888 888 888
|
||||
888 " 888 Y8b. 888 888 888 Y88b d88P Y8b. 888 888 888 Y88b. 888 888
|
||||
888 888 "Y8888 888 888 888 "Y8888P" "Y8888 "Y888888 888 "Y8888P 888 888
|
||||
"#;
|
||||
|
||||
println!("{}", ascii_name);
|
||||
|
||||
info!("Database path: {:?}", opt.db_path);
|
||||
info!("Start server on: {:?}", opt.http_addr);
|
||||
info!("Environment: {:?}", opt.env);
|
||||
info!("Commit SHA: {:?}", env!("VERGEN_SHA").to_string());
|
||||
info!("Build date: {:?}", env!("VERGEN_BUILD_TIMESTAMP").to_string());
|
||||
info!("Package version: {:?}", env!("CARGO_PKG_VERSION").to_string());
|
||||
|
||||
if let Some(master_key) = &data.api_keys.master {
|
||||
info!("Master Key: {:?}", master_key);
|
||||
|
||||
if let Some(private_key) = &data.api_keys.private {
|
||||
info!("Private Key: {:?}", private_key);
|
||||
}
|
||||
|
||||
if let Some(public_key) = &data.api_keys.public {
|
||||
info!("Public Key: {:?}", public_key);
|
||||
}
|
||||
} else {
|
||||
info!("No master key found; The server will have no securities.\
|
||||
If you need some protection in development mode, please export a key. export MEILI_MASTER_KEY=xxx");
|
||||
}
|
||||
|
||||
info!("If you need extra information; Please refer to the documentation: http://docs.meilisearch.com");
|
||||
info!("If you want to support us or help us; Please consult our Github repo: http://github.com/meilisearch/meilisearch");
|
||||
info!("If you want to contact us; Please chat with us on http://meilisearch.com or by email to bonjour@meilisearch.com");
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
use structopt::StructOpt;
|
||||
|
||||
const POSSIBLE_ENV: [&str; 2] = ["development", "production"];
|
||||
|
||||
#[derive(Debug, Clone, StructOpt)]
|
||||
pub struct Opt {
|
||||
/// The destination where the database must be created.
|
||||
@ -14,6 +16,13 @@ pub struct Opt {
|
||||
#[structopt(long, env = "MEILI_MASTER_KEY")]
|
||||
pub master_key: Option<String>,
|
||||
|
||||
/// This environment variable must be set to `production` if your are running in production.
|
||||
/// Could be `production` or `development`
|
||||
/// - `production`: Force api keys
|
||||
/// - `development`: Show logs in "info" mode + not mendatory to specify the api keys
|
||||
#[structopt(long, env = "MEILI_ENV", default_value = "development", possible_values = &POSSIBLE_ENV)]
|
||||
pub env: String,
|
||||
|
||||
/// Do not send analytics to Meili.
|
||||
#[structopt(long, env = "MEILI_NO_ANALYTICS")]
|
||||
pub no_analytics: bool,
|
||||
|
@ -23,6 +23,7 @@ pub fn setup_server() -> Result<TestBackend<Service<Data>>, Box<dyn Error>> {
|
||||
db_path: tmp_dir.path().to_str().unwrap().to_string(),
|
||||
http_addr: "127.0.0.1:7700".to_owned(),
|
||||
master_key: None,
|
||||
env: "development".to_owned(),
|
||||
no_analytics: true,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user