Skip to content

Commit

Permalink
Merge branch 'main' into registries
Browse files Browse the repository at this point in the history
  • Loading branch information
Janaka-Steph authored Nov 2, 2023
2 parents 092b5bd + 501a9b2 commit c226ce9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
3 changes: 1 addition & 2 deletions docker-compose.gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ services:

premd:
container_name: premd
image: ghcr.io/premai-io/premd:7af3782b00f6176b34840f608327c051502511ce
image: ghcr.io/premai-io/premd:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- PREM_REGISTRY_URL=https://raw.githubusercontent.com/premAI-io/prem-registry/main/manifests.json
- PROXY_ENABLED=True
- DOCKER_NETWORK=prem-app_default
labels:
- "traefik.enable=true"
- "traefik.http.routers.premd.rule=PathPrefix(`/premd`)"
Expand Down
72 changes: 52 additions & 20 deletions src-tauri/src/swarm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use reqwest::get;
use serde::Deserialize;
use std::{collections::HashMap, env, path::PathBuf, str};
use std::{
collections::HashMap,
env,
path::PathBuf,
str,
thread::{self, JoinHandle},
time::Duration,
};
use tauri::api::process::Command;

#[derive(Deserialize)]
Expand Down Expand Up @@ -88,13 +95,10 @@ pub async fn get_petals_models() -> Result<Vec<String>, String> {

#[tauri::command]
pub fn is_swarm_mode_running() -> bool {
let output_value = get_swarm_processes();
let processes = get_swarm_processes();

if !output_value.is_empty() {
println!(
"πŸƒβ€β™€οΈ Processeses running: {}",
output_value.replace("\n", " ")
);
if processes.len() > 0 {
println!("πŸƒβ€β™€οΈ Processeses running: {:?}", processes);
return true;
}
return false;
Expand Down Expand Up @@ -165,7 +169,7 @@ fn get_petals_path(handle: tauri::AppHandle) -> String {
petals_path.to_string()
}

pub fn get_swarm_processes() -> String {
pub fn get_swarm_processes() -> Vec<u64> {
// Check if create_env.sh is running
let output = Command::new("/usr/bin/pgrep")
.args(&["-f", "create_env.sh|(mamba|conda).*create.*prem_app"])
Expand All @@ -179,7 +183,7 @@ pub fn get_swarm_processes() -> String {

// If create_env.sh is running, return an empty string
if !output_value.is_empty() {
return "".to_string();
return vec![];
}

let config = Config::new();
Expand All @@ -204,25 +208,53 @@ pub fn get_swarm_processes() -> String {
});

let output_value = output.unwrap().stdout;
output_value
let processes: Vec<u64> = output_value
.replace("\n", " ")
.split(" ")
.collect::<Vec<&str>>()
.into_iter()
.filter_map(|s| s.parse::<u64>().ok())
.collect();
processes
}

#[tauri::command]
pub fn stop_swarm_mode() {
println!("πŸ›‘ Stopping the Swarm...");
let processes = get_swarm_processes().replace("\n", " ");
println!("πŸ›‘ Stopping Processes: {}", processes);
let processes = processes.split(" ").collect::<Vec<&str>>();
let processes = get_swarm_processes();
println!("πŸ›‘ Stopping Processes: {:?}", processes);

for process in processes {
println!("πŸ›‘ Stopping Process: {}", process);
let _ = Command::new("kill")
.args(&[process.to_string()])
.output()
.map_err(|e| {
println!("πŸ™ˆ Failed to execute command: {}", e);
e
});
.args(["-s", "SIGTERM", &process.to_string()])
.spawn()
.expect("πŸ™ˆ Failed to execute kill command with SIGTERM");

let handle: JoinHandle<_> = thread::spawn(move || {
thread::sleep(Duration::from_millis(50));
match Command::new("ps")
.args(["-p", &process.to_string()])
.output()
{
Ok(output) => match output.status.code() {
Some(0) => true,
_ => false,
},
Err(e) => {
eprintln!("Error executing ps command: {}", e);
false
}
}
});
if handle.join().unwrap() {
let _ = Command::new("kill")
.args(["-s", "SIGKILL", &process.to_string()])
.output()
.expect("πŸ™ˆ Failed to execute kill command with SIGKILL");
println!("πŸ›‘ Stopping Process with SIGKILL: {}", process);
} else {
println!("πŸ›‘ Stopping Process with SIGTERM: {}", process);
}
}
println!("πŸ›‘ Stopped all the Swarm Processes.");
}
1 change: 0 additions & 1 deletion src/controller/serviceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class ServiceController implements IServiceController {
if (serviceType === "docker") {
useSettingStore.getState().addServiceAsDownloading(serviceId);
await this.dockerController.download({ serviceId, afterSuccess });
useSettingStore.getState().removeServiceAsDownloading(serviceId);
} else if (serviceType === "binary") {
useSettingStore.getState().addServiceAsDownloading(serviceId);
await this.binariesController.download({
Expand Down

0 comments on commit c226ce9

Please sign in to comment.