mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-27 05:37:31 +01:00
Kill Meilisearch with a TERM signal
This commit is contained in:
parent
eaa897d983
commit
04a24a9239
@ -129,6 +129,11 @@ async fn try_main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
print_launch_resume(&opt, analytics.clone(), config_read_from);
|
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?;
|
run_http(index_scheduler, auth_controller, opt, log_handle, Arc::new(analytics)).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1,23 +1,56 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{bail, Context as _};
|
use anyhow::{bail, Context as _};
|
||||||
|
use tokio::process::Command;
|
||||||
|
use tokio::time;
|
||||||
|
|
||||||
use super::assets::Asset;
|
use super::assets::Asset;
|
||||||
use super::client::Client;
|
use super::client::Client;
|
||||||
use super::workload::Workload;
|
use super::workload::Workload;
|
||||||
|
|
||||||
pub async fn kill(mut meilisearch: tokio::process::Child) {
|
pub async fn kill(mut meilisearch: tokio::process::Child) {
|
||||||
if let Err(error) = meilisearch.kill().await {
|
let Some(id) = meilisearch.id() else { return };
|
||||||
tracing::warn!(
|
|
||||||
error = &error as &dyn std::error::Error,
|
match Command::new("kill").args(["--signal=TERM", &id.to_string()]).spawn() {
|
||||||
"while terminating Meilisearch server"
|
Ok(mut cmd) => {
|
||||||
)
|
let Err(error) = cmd.wait().await else { return };
|
||||||
|
tracing::warn!(
|
||||||
|
error = &error as &dyn std::error::Error,
|
||||||
|
"while awaiting the Meilisearch server kill"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
tracing::warn!(
|
||||||
|
error = &error as &dyn std::error::Error,
|
||||||
|
"while terminating Meilisearch server with a kill -s TERM"
|
||||||
|
);
|
||||||
|
if let Err(error) = meilisearch.kill().await {
|
||||||
|
tracing::warn!(
|
||||||
|
error = &error as &dyn std::error::Error,
|
||||||
|
"while terminating Meilisearch server"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match time::timeout(Duration::from_secs(5), meilisearch.wait()).await {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => {
|
||||||
|
if let Err(error) = meilisearch.kill().await {
|
||||||
|
tracing::warn!(
|
||||||
|
error = &error as &dyn std::error::Error,
|
||||||
|
"while terminating Meilisearch server"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn build() -> anyhow::Result<()> {
|
pub async fn build() -> anyhow::Result<()> {
|
||||||
let mut command = tokio::process::Command::new("cargo");
|
let mut command = Command::new("cargo");
|
||||||
command.arg("build").arg("--release").arg("-p").arg("meilisearch");
|
command.arg("build").arg("--release").arg("-p").arg("meilisearch");
|
||||||
|
|
||||||
command.kill_on_drop(true);
|
command.kill_on_drop(true);
|
||||||
@ -37,7 +70,7 @@ pub async fn start(
|
|||||||
master_key: Option<&str>,
|
master_key: Option<&str>,
|
||||||
workload: &Workload,
|
workload: &Workload,
|
||||||
asset_folder: &str,
|
asset_folder: &str,
|
||||||
mut command: tokio::process::Command,
|
mut command: Command,
|
||||||
) -> anyhow::Result<tokio::process::Child> {
|
) -> anyhow::Result<tokio::process::Child> {
|
||||||
command.arg("--db-path").arg("./_xtask_benchmark.ms");
|
command.arg("--db-path").arg("./_xtask_benchmark.ms");
|
||||||
if let Some(master_key) = master_key {
|
if let Some(master_key) = master_key {
|
||||||
@ -77,7 +110,7 @@ async fn wait_for_health(
|
|||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
time::sleep(Duration::from_millis(500)).await;
|
||||||
// check whether the Meilisearch instance exited early (cut the wait)
|
// check whether the Meilisearch instance exited early (cut the wait)
|
||||||
if let Some(exit_code) =
|
if let Some(exit_code) =
|
||||||
meilisearch.try_wait().context("cannot check Meilisearch server process status")?
|
meilisearch.try_wait().context("cannot check Meilisearch server process status")?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user