Repository: meilisearch/meilisearch
File: crates/meilisearch/src/main.rs (Rust)

Code before:
                master_key.len(),
                generated_master_key_message(),
            )
        }
        ("production", None) => {
            anyhow::bail!(
                "You must provide a master key to secure your instance in a production environment. It can be specified via the MEILI_MASTER_KEY environment variable or the --master-key launch option.

{}",
                generated_master_key_message()
            )
        }
        // No error; continue
        _ => (),
    }

    let (index_scheduler, auth_controller) = setup_meilisearch(&opt)?;

    let analytics =
        analytics::Analytics::new(&opt, index_scheduler.clone(), auth_controller.clone()).await;

    print_launch_resume(&opt, analytics.clone(), config_read_from);

    tokio::spawn(async move {
        tokio::signal::ctrl_c().await.unwrap();
        std::process::exit(77);
    });

    run_http(index_scheduler, auth_controller, opt, log_handle, Arc::new(analytics)).await?;

    Ok(())
}

async fn run_http(
    index_scheduler: Arc<IndexScheduler>,
    auth_controller: Arc<AuthController>,
    opt: Opt,
    logs: (LogRouteHandle, LogStderrHandle),
    analytics: Arc<Analytics>,
) -> anyhow::Result<()> {
    let enable_dashboard = &opt.env == "development";
    let opt_clone = opt.clone();
    let index_scheduler = Data::from(index_scheduler);
    let auth_controller = Data::from(auth_controller);
    let analytics = Data::from(analytics);
    let search_queue = SearchQueue::new(
        opt.experimental_search_queue_size,
        available_parallelism()
            .unwrap_or(NonZeroUsize::new(2).unwrap())
            .checked_mul(opt.experimental_nb_searches_per_core)
            .unwrap_or(NonZeroUsize::MAX),

Review comment (suggestion):
Not sure what value to use, now that we tested with `77`.

On UNIX, the value when a signal is not used is 128 + n where n is the signal code. SIGTERM is usually 2, so 130?

```suggestion
        std::process::exit(130);
```

Code after:
                master_key.len(),
                generated_master_key_message(),
            )
        }
        ("production", None) => {
            anyhow::bail!(
                "You must provide a master key to secure your instance in a production environment. It can be specified via the MEILI_MASTER_KEY environment variable or the --master-key launch option.

{}",
                generated_master_key_message()
            )
        }
        // No error; continue
        _ => (),
    }

    let (index_scheduler, auth_controller) = setup_meilisearch(&opt)?;

    let analytics =
        analytics::Analytics::new(&opt, index_scheduler.clone(), auth_controller.clone()).await;

    print_launch_resume(&opt, analytics.clone(), config_read_from);

    tokio::spawn(async move {
        tokio::signal::ctrl_c().await.unwrap();
        std::process::exit(130);
    });

    run_http(index_scheduler, auth_controller, opt, log_handle, Arc::new(analytics)).await?;

    Ok(())
}

async fn run_http(
    index_scheduler: Arc<IndexScheduler>,
    auth_controller: Arc<AuthController>,
    opt: Opt,
    logs: (LogRouteHandle, LogStderrHandle),
    analytics: Arc<Analytics>,
) -> anyhow::Result<()> {
    let enable_dashboard = &opt.env == "development";
    let opt_clone = opt.clone();
    let index_scheduler = Data::from(index_scheduler);
    let auth_controller = Data::from(auth_controller);
    let analytics = Data::from(analytics);
    let search_queue = SearchQueue::new(
        opt.experimental_search_queue_size,
        available_parallelism()
            .unwrap_or(NonZeroUsize::new(2).unwrap())
            .checked_mul(opt.experimental_nb_searches_per_core)
            .unwrap_or(NonZeroUsize::MAX),