fix: Add #[cfg(unix)] guards for nix crate imports and signal handling
- postgres.rs, minio.rs, redis.rs: Wrap nix::sys::signal and nix::unistd imports with #[cfg(unix)] to allow compilation on Windows - Use child.kill() as fallback on non-unix platforms for process management
This commit is contained in:
parent
d03e13d2eb
commit
dc3f67ca87
3 changed files with 90 additions and 18 deletions
|
|
@ -1,6 +1,8 @@
|
|||
use super::{check_tcp_port, ensure_dir, wait_for, HEALTH_CHECK_INTERVAL, HEALTH_CHECK_TIMEOUT};
|
||||
use anyhow::{Context, Result};
|
||||
#[cfg(unix)]
|
||||
use nix::sys::signal::{kill, Signal};
|
||||
#[cfg(unix)]
|
||||
use nix::unistd::Pid;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -394,8 +396,13 @@ impl MinioService {
|
|||
if let Some(ref mut child) = self.process {
|
||||
log::info!("Stopping MinIO...");
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGTERM);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
|
||||
for _ in 0..50 {
|
||||
match child.try_wait() {
|
||||
|
|
@ -408,7 +415,13 @@ impl MinioService {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGKILL);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
self.process = None;
|
||||
}
|
||||
|
|
@ -427,12 +440,23 @@ impl MinioService {
|
|||
impl Drop for MinioService {
|
||||
fn drop(&mut self) {
|
||||
if let Some(ref mut child) = self.process {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGTERM);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
|
||||
std::thread::sleep(Duration::from_millis(500));
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGKILL);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
use super::{check_tcp_port, ensure_dir, wait_for, HEALTH_CHECK_INTERVAL, HEALTH_CHECK_TIMEOUT};
|
||||
use anyhow::{Context, Result};
|
||||
#[cfg(unix)]
|
||||
use nix::sys::signal::{kill, Signal};
|
||||
#[cfg(unix)]
|
||||
use nix::unistd::Pid;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Child, Command, Stdio};
|
||||
|
|
@ -427,8 +429,13 @@ unix_socket_directories = '{}'
|
|||
if let Some(ref mut child) = self.process {
|
||||
log::info!("Stopping PostgreSQL...");
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGTERM);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
|
||||
for _ in 0..50 {
|
||||
match child.try_wait() {
|
||||
|
|
@ -441,7 +448,13 @@ unix_socket_directories = '{}'
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGKILL);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
self.process = None;
|
||||
}
|
||||
|
|
@ -460,12 +473,23 @@ unix_socket_directories = '{}'
|
|||
impl Drop for PostgresService {
|
||||
fn drop(&mut self) {
|
||||
if let Some(ref mut child) = self.process {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGTERM);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
|
||||
std::thread::sleep(Duration::from_millis(500));
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGKILL);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
use super::{check_tcp_port, ensure_dir, wait_for, HEALTH_CHECK_INTERVAL, HEALTH_CHECK_TIMEOUT};
|
||||
use anyhow::{Context, Result};
|
||||
#[cfg(unix)]
|
||||
use nix::sys::signal::{kill, Signal};
|
||||
#[cfg(unix)]
|
||||
use nix::unistd::Pid;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Child, Command, Stdio};
|
||||
|
|
@ -368,8 +370,13 @@ impl RedisService {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGTERM);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
|
||||
for _ in 0..20 {
|
||||
match child.try_wait() {
|
||||
|
|
@ -382,7 +389,13 @@ impl RedisService {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGKILL);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
self.process = None;
|
||||
}
|
||||
|
|
@ -415,12 +428,23 @@ impl Drop for RedisService {
|
|||
std::thread::sleep(Duration::from_millis(200));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGTERM);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
|
||||
std::thread::sleep(Duration::from_millis(300));
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pid = Pid::from_raw(child.id() as i32);
|
||||
let _ = kill(pid, Signal::SIGKILL);
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue