forked from blasthavers/blastmud
Don't kill process if pidfile has own pid.
This commit is contained in:
parent
0cdf8a8810
commit
1401292b23
@ -2,7 +2,7 @@ use std::fs::{read_to_string, write};
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use log::info;
|
use log::info;
|
||||||
use nix::{sys::signal::{kill, Signal}, unistd::Pid};
|
use nix::{sys::signal::{kill, Signal}, unistd::{Pid, getpid}};
|
||||||
use crate::DResult;
|
use crate::DResult;
|
||||||
|
|
||||||
pub fn replace_old_gameserver(pidfile: &str) -> DResult<()> {
|
pub fn replace_old_gameserver(pidfile: &str) -> DResult<()> {
|
||||||
@ -17,6 +17,10 @@ pub fn replace_old_gameserver(pidfile: &str) -> DResult<()> {
|
|||||||
}
|
}
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
let pid: Pid = Pid::from_raw(f.parse().map_err(|e| Box::new(e) as Box::<dyn Error + Send + Sync>)?);
|
let pid: Pid = Pid::from_raw(f.parse().map_err(|e| Box::new(e) as Box::<dyn Error + Send + Sync>)?);
|
||||||
|
if pid == getpid() {
|
||||||
|
info!("Pid in pidfile is me - ignoring");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
match read_to_string(format!("/proc/{}/cmdline", pid)) {
|
match read_to_string(format!("/proc/{}/cmdline", pid)) {
|
||||||
Ok(content) =>
|
Ok(content) =>
|
||||||
if content.contains("blastmud_game") {
|
if content.contains("blastmud_game") {
|
||||||
|
@ -25,7 +25,7 @@ use warp::{
|
|||||||
self, filters::ws, Filter, Reply
|
self, filters::ws, Filter, Reply
|
||||||
};
|
};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use nix::{sys::signal::{kill, Signal}, unistd::Pid};
|
use nix::{sys::signal::{kill, Signal}, unistd::{Pid, getpid}};
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct Config {
|
struct Config {
|
||||||
@ -652,6 +652,10 @@ pub fn replace_old_listener(pidfile: &str) -> DResult<()> {
|
|||||||
}
|
}
|
||||||
Ok(f) => {
|
Ok(f) => {
|
||||||
let pid: Pid = Pid::from_raw(f.parse().map_err(|e| Box::new(e) as Box::<dyn Error + Send + Sync>)?);
|
let pid: Pid = Pid::from_raw(f.parse().map_err(|e| Box::new(e) as Box::<dyn Error + Send + Sync>)?);
|
||||||
|
if pid == getpid() {
|
||||||
|
info!("Pid in pidfile is me - ignoring");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
match fs::read_to_string(format!("/proc/{}/cmdline", pid)) {
|
match fs::read_to_string(format!("/proc/{}/cmdline", pid)) {
|
||||||
Ok(content) =>
|
Ok(content) =>
|
||||||
if content.contains("blastmud_listener") {
|
if content.contains("blastmud_listener") {
|
||||||
|
Loading…
Reference in New Issue
Block a user