change the FileStore::is_open() to try to connect to the sock to tetermine if a FileStore is open instead of a PID file. because when deploying with docker a process with the same PID can be running (and often is the mize process itself)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use core::result::Result::Err;
|
||||
use core::unimplemented;
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
@@ -63,16 +65,8 @@ pub fn create(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
|
||||
pub fn is_running(sub_matches: &ArgMatches) -> MizeResult<()> {
|
||||
|
||||
let home_dir = env!("HOME");
|
||||
|
||||
if FileStore::store_is_opened(home_dir.to_owned() + "/.mize")? {
|
||||
println!("true");
|
||||
} else {
|
||||
println!("false");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
println!("not implemented");
|
||||
Err(mize_err!("not implemented"))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@ use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::fs::OpenOptions;
|
||||
use sysinfo::{System, Pid, ProcessRefreshKind, RefreshKind};
|
||||
use tracing::field::debug;
|
||||
use std::io::Write;
|
||||
use ciborium::Value as CborValue;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::instance::store::IdIter;
|
||||
use crate::item::IntoItemData;
|
||||
@@ -13,7 +15,8 @@ use crate::error::{IntoMizeResult, MizeResult, MizeError};
|
||||
use crate::core::item::{ItemData, Item};
|
||||
use crate::core::id::MizeId;
|
||||
use crate::item::get_raw_from_cbor;
|
||||
use crate::instance::Instance;
|
||||
use crate::instance::{self, Instance};
|
||||
use tokio::net::UnixStream;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FileStore {
|
||||
@@ -29,6 +32,7 @@ impl FileStore {
|
||||
fs::create_dir_all(Path::new(&path).join("store"))?;
|
||||
|
||||
// check for valid pid file
|
||||
/*
|
||||
if let Some(pid) = valid_pid_file(path)? {
|
||||
// store already opened
|
||||
return Err(mize_err!("MizeStore at path {} is already opened by process with pid {}", path.display(), pid));
|
||||
@@ -40,6 +44,7 @@ impl FileStore {
|
||||
let mut file = OpenOptions::new().write(true).create(true).open(path.join("pid"))?;
|
||||
write!(file, "{}", pid)?;
|
||||
}
|
||||
*/
|
||||
|
||||
// init the store
|
||||
if !path.join("next_id").exists() {
|
||||
@@ -49,9 +54,24 @@ impl FileStore {
|
||||
Ok(FileStore { path: Path::new(&path).to_owned() })
|
||||
}
|
||||
|
||||
pub fn store_is_opened(store_path: String) -> MizeResult<bool> {
|
||||
let res = valid_pid_file(Path::new(&store_path))?.is_some();
|
||||
Ok(res)
|
||||
pub fn store_is_opened(store_path: String, instance: &mut Instance) -> MizeResult<bool> {
|
||||
|
||||
// this was the old method....
|
||||
//let valid_pid_file = valid_pid_file(Path::new(&store_path))?.is_some();
|
||||
|
||||
let can_connect_to_sock = match instance.spawn_async_blocking("con_test_thread", try_connect_to_sock(store_path.clone())) {
|
||||
Ok(_) => true,
|
||||
Err(_) => false,
|
||||
};
|
||||
debug!("MiZe Store at {} opened: {}", store_path, can_connect_to_sock);
|
||||
Ok(can_connect_to_sock)
|
||||
}
|
||||
}
|
||||
|
||||
async fn try_connect_to_sock(store_path: String) -> MizeResult<()> {
|
||||
match UnixStream::connect(PathBuf::from(store_path).join("sock")).await {
|
||||
Err(_) => Err(mize_err!("")),
|
||||
Ok(_) => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
use clap::builder::OsStr;
|
||||
use clap::{ArgAction, ArgMatches};
|
||||
use clap::{Arg, crate_version, Command};
|
||||
@@ -80,6 +81,7 @@ fn main() {
|
||||
|
||||
if let Err(err) = result {
|
||||
err.log();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ pub fn os_instance_init(instance: &mut Instance) -> MizeResult<()> {
|
||||
},
|
||||
};
|
||||
|
||||
if FileStore::store_is_opened(store_path.to_owned())? {
|
||||
if FileStore::store_is_opened(store_path.to_owned(), instance)? {
|
||||
// if the store is already opened, connect to the instance, that opened it and join
|
||||
// it's namespace
|
||||
|
||||
@@ -114,7 +114,7 @@ pub fn os_instance_init(instance: &mut Instance) -> MizeResult<()> {
|
||||
|
||||
#[cfg(target_family = "windows")]
|
||||
{
|
||||
error!("CONNECTING... would connect, but that is not imon't identify as anything, to not cause anyone problems... So that everybody can be satisfied...plemented on windows yet");
|
||||
error!("CONNECTING... would connect, but that is not implemented on windows yet");
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user