fix: clean up cortex processes (#5215)
* fix: clean up cortex processes * chore: clean up * chore: does not need output shell
This commit is contained in:
parent
ecfbdf8256
commit
6d6790d5e0
@ -50,8 +50,6 @@ export default class JanEngineManagementExtension extends EngineManagementExtens
|
|||||||
* Called when the extension is loaded.
|
* Called when the extension is loaded.
|
||||||
*/
|
*/
|
||||||
async onLoad() {
|
async onLoad() {
|
||||||
// Symlink Engines Directory
|
|
||||||
await executeOnMain(NODE, 'symlinkEngines')
|
|
||||||
// Update default local engine
|
// Update default local engine
|
||||||
this.updateDefaultEngine()
|
this.updateDefaultEngine()
|
||||||
|
|
||||||
|
|||||||
@ -174,7 +174,6 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
|
|||||||
console.log('Clean up cortex.cpp services')
|
console.log('Clean up cortex.cpp services')
|
||||||
this.shouldReconnect = false
|
this.shouldReconnect = false
|
||||||
this.clean()
|
this.clean()
|
||||||
await executeOnMain(NODE, 'dispose')
|
|
||||||
super.onUnload()
|
super.onUnload()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,8 +10,8 @@ use tauri::{App, Emitter, Listener, Manager};
|
|||||||
use tauri_plugin_shell::process::{CommandChild, CommandEvent};
|
use tauri_plugin_shell::process::{CommandChild, CommandEvent};
|
||||||
use tauri_plugin_shell::ShellExt;
|
use tauri_plugin_shell::ShellExt;
|
||||||
use tauri_plugin_store::StoreExt;
|
use tauri_plugin_store::StoreExt;
|
||||||
use tokio::sync::Mutex; // Using tokio::sync::Mutex
|
|
||||||
use tokio::time::{sleep, Duration};
|
use tokio::time::{sleep, Duration};
|
||||||
|
use tokio::{process::Command, sync::Mutex}; // Using tokio::sync::Mutex
|
||||||
// MCP
|
// MCP
|
||||||
use super::{
|
use super::{
|
||||||
cmd::{get_jan_data_folder_path, get_jan_extensions_path},
|
cmd::{get_jan_data_folder_path, get_jan_extensions_path},
|
||||||
@ -211,6 +211,7 @@ pub fn setup_mcp(app: &App) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_sidecar(app: &App) -> Result<(), String> {
|
pub fn setup_sidecar(app: &App) -> Result<(), String> {
|
||||||
|
clean_up();
|
||||||
let app_handle = app.handle().clone();
|
let app_handle = app.handle().clone();
|
||||||
let app_handle_for_spawn = app_handle.clone();
|
let app_handle_for_spawn = app_handle.clone();
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
@ -225,6 +226,7 @@ pub fn setup_sidecar(app: &App) -> Result<(), String> {
|
|||||||
let mut cmd = app_handle_for_spawn
|
let mut cmd = app_handle_for_spawn
|
||||||
.shell()
|
.shell()
|
||||||
.sidecar("cortex-server")
|
.sidecar("cortex-server")
|
||||||
|
|
||||||
.expect("Failed to get sidecar command")
|
.expect("Failed to get sidecar command")
|
||||||
.args([
|
.args([
|
||||||
"--start-server",
|
"--start-server",
|
||||||
@ -410,6 +412,34 @@ pub fn setup_sidecar(app: &App) -> Result<(), String> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Clean up function to kill the sidecar process
|
||||||
|
//
|
||||||
|
pub fn clean_up() {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
let _ = std::process::Command::new("taskkill")
|
||||||
|
.args(["-f", "-im", "llama-server.exe"])
|
||||||
|
.creation_flags(0x08000000)
|
||||||
|
.spawn();
|
||||||
|
let _ = std::process::Command::new("taskkill")
|
||||||
|
.args(["-f", "-im", "cortex-server.exe"])
|
||||||
|
.creation_flags(0x08000000)
|
||||||
|
.spawn();
|
||||||
|
}
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
let _ = std::process::Command::new("pkill")
|
||||||
|
.args(["-f", "llama-server"])
|
||||||
|
.spawn();
|
||||||
|
let _ = std::process::Command::new("pkill")
|
||||||
|
.args(["-f", "cortex-server"])
|
||||||
|
.spawn();
|
||||||
|
}
|
||||||
|
log::info!("Clean up function executed, sidecar processes killed.");
|
||||||
|
}
|
||||||
|
|
||||||
fn copy_dir_all(src: PathBuf, dst: PathBuf) -> Result<(), String> {
|
fn copy_dir_all(src: PathBuf, dst: PathBuf) -> Result<(), String> {
|
||||||
fs::create_dir_all(&dst).map_err(|e| e.to_string())?;
|
fs::create_dir_all(&dst).map_err(|e| e.to_string())?;
|
||||||
log::info!("Copying from {:?} to {:?}", src, dst);
|
log::info!("Copying from {:?} to {:?}", src, dst);
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use std::{collections::HashMap, sync::Arc};
|
|||||||
use tauri::Emitter;
|
use tauri::Emitter;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use reqwest::blocking::Client;
|
use crate::core::setup::clean_up;
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
@ -120,11 +120,8 @@ pub fn run() {
|
|||||||
.on_window_event(|window, event| match event {
|
.on_window_event(|window, event| match event {
|
||||||
tauri::WindowEvent::CloseRequested { .. } => {
|
tauri::WindowEvent::CloseRequested { .. } => {
|
||||||
if window.label() == "main" {
|
if window.label() == "main" {
|
||||||
let client = Client::new();
|
|
||||||
let url = "http://127.0.0.1:39291/processManager/destroy";
|
|
||||||
let _ = client.delete(url).send();
|
|
||||||
|
|
||||||
window.emit("kill-sidecar", ()).unwrap();
|
window.emit("kill-sidecar", ()).unwrap();
|
||||||
|
clean_up();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user