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 super::{check_tcp_port, ensure_dir, wait_for, HEALTH_CHECK_INTERVAL, HEALTH_CHECK_TIMEOUT};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
#[cfg(unix)]
|
||||||
use nix::sys::signal::{kill, Signal};
|
use nix::sys::signal::{kill, Signal};
|
||||||
|
#[cfg(unix)]
|
||||||
use nix::unistd::Pid;
|
use nix::unistd::Pid;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
@ -394,8 +396,13 @@ impl MinioService {
|
||||||
if let Some(ref mut child) = self.process {
|
if let Some(ref mut child) = self.process {
|
||||||
log::info!("Stopping MinIO...");
|
log::info!("Stopping MinIO...");
|
||||||
|
|
||||||
let pid = Pid::from_raw(child.id() as i32);
|
#[cfg(unix)]
|
||||||
let _ = kill(pid, Signal::SIGTERM);
|
{
|
||||||
|
let pid = Pid::from_raw(child.id() as i32);
|
||||||
|
let _ = kill(pid, Signal::SIGTERM);
|
||||||
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
let _ = child.kill();
|
||||||
|
|
||||||
for _ in 0..50 {
|
for _ in 0..50 {
|
||||||
match child.try_wait() {
|
match child.try_wait() {
|
||||||
|
|
@ -408,7 +415,13 @@ impl MinioService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = kill(pid, Signal::SIGKILL);
|
#[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();
|
let _ = child.wait();
|
||||||
self.process = None;
|
self.process = None;
|
||||||
}
|
}
|
||||||
|
|
@ -427,12 +440,23 @@ impl MinioService {
|
||||||
impl Drop for MinioService {
|
impl Drop for MinioService {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Some(ref mut child) = self.process {
|
if let Some(ref mut child) = self.process {
|
||||||
let pid = Pid::from_raw(child.id() as i32);
|
#[cfg(unix)]
|
||||||
let _ = kill(pid, Signal::SIGTERM);
|
{
|
||||||
|
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));
|
std::thread::sleep(Duration::from_millis(500));
|
||||||
|
|
||||||
let _ = kill(pid, Signal::SIGKILL);
|
#[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();
|
let _ = child.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
use super::{check_tcp_port, ensure_dir, wait_for, HEALTH_CHECK_INTERVAL, HEALTH_CHECK_TIMEOUT};
|
use super::{check_tcp_port, ensure_dir, wait_for, HEALTH_CHECK_INTERVAL, HEALTH_CHECK_TIMEOUT};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
#[cfg(unix)]
|
||||||
use nix::sys::signal::{kill, Signal};
|
use nix::sys::signal::{kill, Signal};
|
||||||
|
#[cfg(unix)]
|
||||||
use nix::unistd::Pid;
|
use nix::unistd::Pid;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Child, Command, Stdio};
|
use std::process::{Child, Command, Stdio};
|
||||||
|
|
@ -427,8 +429,13 @@ unix_socket_directories = '{}'
|
||||||
if let Some(ref mut child) = self.process {
|
if let Some(ref mut child) = self.process {
|
||||||
log::info!("Stopping PostgreSQL...");
|
log::info!("Stopping PostgreSQL...");
|
||||||
|
|
||||||
let pid = Pid::from_raw(child.id() as i32);
|
#[cfg(unix)]
|
||||||
let _ = kill(pid, Signal::SIGTERM);
|
{
|
||||||
|
let pid = Pid::from_raw(child.id() as i32);
|
||||||
|
let _ = kill(pid, Signal::SIGTERM);
|
||||||
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
let _ = child.kill();
|
||||||
|
|
||||||
for _ in 0..50 {
|
for _ in 0..50 {
|
||||||
match child.try_wait() {
|
match child.try_wait() {
|
||||||
|
|
@ -441,7 +448,13 @@ unix_socket_directories = '{}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = kill(pid, Signal::SIGKILL);
|
#[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();
|
let _ = child.wait();
|
||||||
self.process = None;
|
self.process = None;
|
||||||
}
|
}
|
||||||
|
|
@ -460,12 +473,23 @@ unix_socket_directories = '{}'
|
||||||
impl Drop for PostgresService {
|
impl Drop for PostgresService {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Some(ref mut child) = self.process {
|
if let Some(ref mut child) = self.process {
|
||||||
let pid = Pid::from_raw(child.id() as i32);
|
#[cfg(unix)]
|
||||||
let _ = kill(pid, Signal::SIGTERM);
|
{
|
||||||
|
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));
|
std::thread::sleep(Duration::from_millis(500));
|
||||||
|
|
||||||
let _ = kill(pid, Signal::SIGKILL);
|
#[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();
|
let _ = child.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
use super::{check_tcp_port, ensure_dir, wait_for, HEALTH_CHECK_INTERVAL, HEALTH_CHECK_TIMEOUT};
|
use super::{check_tcp_port, ensure_dir, wait_for, HEALTH_CHECK_INTERVAL, HEALTH_CHECK_TIMEOUT};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
#[cfg(unix)]
|
||||||
use nix::sys::signal::{kill, Signal};
|
use nix::sys::signal::{kill, Signal};
|
||||||
|
#[cfg(unix)]
|
||||||
use nix::unistd::Pid;
|
use nix::unistd::Pid;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{Child, Command, Stdio};
|
use std::process::{Child, Command, Stdio};
|
||||||
|
|
@ -368,8 +370,13 @@ impl RedisService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let pid = Pid::from_raw(child.id() as i32);
|
#[cfg(unix)]
|
||||||
let _ = kill(pid, Signal::SIGTERM);
|
{
|
||||||
|
let pid = Pid::from_raw(child.id() as i32);
|
||||||
|
let _ = kill(pid, Signal::SIGTERM);
|
||||||
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
let _ = child.kill();
|
||||||
|
|
||||||
for _ in 0..20 {
|
for _ in 0..20 {
|
||||||
match child.try_wait() {
|
match child.try_wait() {
|
||||||
|
|
@ -382,7 +389,13 @@ impl RedisService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = kill(pid, Signal::SIGKILL);
|
#[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();
|
let _ = child.wait();
|
||||||
self.process = None;
|
self.process = None;
|
||||||
}
|
}
|
||||||
|
|
@ -415,12 +428,23 @@ impl Drop for RedisService {
|
||||||
std::thread::sleep(Duration::from_millis(200));
|
std::thread::sleep(Duration::from_millis(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
let pid = Pid::from_raw(child.id() as i32);
|
#[cfg(unix)]
|
||||||
let _ = kill(pid, Signal::SIGTERM);
|
{
|
||||||
|
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));
|
std::thread::sleep(Duration::from_millis(300));
|
||||||
|
|
||||||
let _ = kill(pid, Signal::SIGKILL);
|
#[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();
|
let _ = child.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue