mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
Fix/quarantine deno (#2466)
* fix: Move the deno embedded into a seperate binary. This should be the quick hacky way of making sure that the memory leaks wont happen * fix:
This commit is contained in:
@@ -11,8 +11,7 @@ use deno_core::{
|
||||
ModuleSourceFuture, ModuleSpecifier, ModuleType, OpDecl, ResolutionKind, RuntimeOptions,
|
||||
Snapshot,
|
||||
};
|
||||
use embassy_container_init::ProcessGroupId;
|
||||
use helpers::{script_dir, spawn_local, Rsync, UnixRpcClient};
|
||||
use helpers::{script_dir, spawn_local, Rsync};
|
||||
use models::{PackageId, ProcedureName, Version, VolumeId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
@@ -101,8 +100,6 @@ struct JsContext {
|
||||
volumes: Arc<dyn PathForVolumeId>,
|
||||
input: Value,
|
||||
variable_args: Vec<serde_json::Value>,
|
||||
container_process_gid: ProcessGroupId,
|
||||
container_rpc_client: Option<Arc<UnixRpcClient>>,
|
||||
rsyncs: Arc<Mutex<(usize, BTreeMap<usize, Rsync>)>>,
|
||||
}
|
||||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
|
||||
@@ -183,8 +180,6 @@ pub struct JsExecutionEnvironment {
|
||||
package_id: PackageId,
|
||||
version: Version,
|
||||
volumes: Arc<dyn PathForVolumeId>,
|
||||
container_process_gid: ProcessGroupId,
|
||||
container_rpc_client: Option<Arc<UnixRpcClient>>,
|
||||
}
|
||||
|
||||
impl JsExecutionEnvironment {
|
||||
@@ -193,8 +188,6 @@ impl JsExecutionEnvironment {
|
||||
package_id: &PackageId,
|
||||
version: &Version,
|
||||
volumes: Box<dyn PathForVolumeId>,
|
||||
container_process_gid: ProcessGroupId,
|
||||
container_rpc_client: Option<Arc<UnixRpcClient>>,
|
||||
) -> Result<JsExecutionEnvironment, (JsError, String)> {
|
||||
let data_dir = data_directory.as_ref();
|
||||
let base_directory = data_dir;
|
||||
@@ -228,8 +221,6 @@ impl JsExecutionEnvironment {
|
||||
version: version.clone(),
|
||||
volumes: volumes.into(),
|
||||
sandboxed: false,
|
||||
container_process_gid,
|
||||
container_rpc_client,
|
||||
})
|
||||
}
|
||||
pub fn read_only_effects(mut self) -> Self {
|
||||
@@ -295,11 +286,7 @@ impl JsExecutionEnvironment {
|
||||
fns::get_variable_args::decl(),
|
||||
fns::set_value::decl(),
|
||||
fns::is_sandboxed::decl(),
|
||||
fns::start_command::decl(),
|
||||
fns::wait_command::decl(),
|
||||
fns::sleep::decl(),
|
||||
fns::send_signal::decl(),
|
||||
fns::signal_group::decl(),
|
||||
fns::rsync::decl(),
|
||||
fns::rsync_wait::decl(),
|
||||
fns::rsync_progress::decl(),
|
||||
@@ -332,8 +319,6 @@ impl JsExecutionEnvironment {
|
||||
sandboxed: self.sandboxed,
|
||||
input,
|
||||
variable_args,
|
||||
container_process_gid: self.container_process_gid,
|
||||
container_rpc_client: self.container_rpc_client.clone(),
|
||||
rsyncs: Default::default(),
|
||||
};
|
||||
let ext = Extension::builder("embassy")
|
||||
@@ -389,20 +374,17 @@ mod fns {
|
||||
use deno_core::anyhow::{anyhow, bail};
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::*;
|
||||
use embassy_container_init::{
|
||||
OutputParams, OutputStrategy, ProcessGroupId, ProcessId, RunCommand, RunCommandParams,
|
||||
SendSignal, SendSignalParams, SignalGroup, SignalGroupParams,
|
||||
};
|
||||
use embassy_container_init::ProcessId;
|
||||
use helpers::{to_tmp_path, AtomicFile, Rsync, RsyncOptions};
|
||||
use itertools::Itertools;
|
||||
use models::VolumeId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::Value;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tokio::process::Command;
|
||||
|
||||
use super::{AnswerState, JsContext};
|
||||
use crate::{system_time_as_unix_ms, MetadataJs, ResultType};
|
||||
use crate::{system_time_as_unix_ms, MetadataJs};
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Default)]
|
||||
struct FetchOptions {
|
||||
@@ -992,18 +974,6 @@ mod fns {
|
||||
let state = state.borrow();
|
||||
state.borrow::<JsContext>().clone()
|
||||
};
|
||||
if let Some(rpc_client) = ctx.container_rpc_client {
|
||||
return rpc_client
|
||||
.request(
|
||||
embassy_container_init::Log,
|
||||
embassy_container_init::LogParams {
|
||||
gid: Some(ctx.container_process_gid),
|
||||
level: embassy_container_init::LogLevel::Trace(input),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow!("{}: {:?}", e.message, e.data));
|
||||
}
|
||||
tracing::trace!(
|
||||
package_id = tracing::field::display(&ctx.package_id),
|
||||
run_function = tracing::field::display(&ctx.run_function),
|
||||
@@ -1018,18 +988,6 @@ mod fns {
|
||||
let state = state.borrow();
|
||||
state.borrow::<JsContext>().clone()
|
||||
};
|
||||
if let Some(rpc_client) = ctx.container_rpc_client {
|
||||
return rpc_client
|
||||
.request(
|
||||
embassy_container_init::Log,
|
||||
embassy_container_init::LogParams {
|
||||
gid: Some(ctx.container_process_gid),
|
||||
level: embassy_container_init::LogLevel::Warn(input),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow!("{}: {:?}", e.message, e.data));
|
||||
}
|
||||
tracing::warn!(
|
||||
package_id = tracing::field::display(&ctx.package_id),
|
||||
run_function = tracing::field::display(&ctx.run_function),
|
||||
@@ -1044,18 +1002,6 @@ mod fns {
|
||||
let state = state.borrow();
|
||||
state.borrow::<JsContext>().clone()
|
||||
};
|
||||
if let Some(rpc_client) = ctx.container_rpc_client {
|
||||
return rpc_client
|
||||
.request(
|
||||
embassy_container_init::Log,
|
||||
embassy_container_init::LogParams {
|
||||
gid: Some(ctx.container_process_gid),
|
||||
level: embassy_container_init::LogLevel::Error(input),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow!("{}: {:?}", e.message, e.data));
|
||||
}
|
||||
tracing::error!(
|
||||
package_id = tracing::field::display(&ctx.package_id),
|
||||
run_function = tracing::field::display(&ctx.run_function),
|
||||
@@ -1070,18 +1016,6 @@ mod fns {
|
||||
let state = state.borrow();
|
||||
state.borrow::<JsContext>().clone()
|
||||
};
|
||||
if let Some(rpc_client) = ctx.container_rpc_client {
|
||||
return rpc_client
|
||||
.request(
|
||||
embassy_container_init::Log,
|
||||
embassy_container_init::LogParams {
|
||||
gid: Some(ctx.container_process_gid),
|
||||
level: embassy_container_init::LogLevel::Debug(input),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow!("{}: {:?}", e.message, e.data));
|
||||
}
|
||||
tracing::debug!(
|
||||
package_id = tracing::field::display(&ctx.package_id),
|
||||
run_function = tracing::field::display(&ctx.run_function),
|
||||
@@ -1092,28 +1026,11 @@ mod fns {
|
||||
}
|
||||
#[op]
|
||||
async fn log_info(state: Rc<RefCell<OpState>>, input: String) -> Result<(), AnyError> {
|
||||
let (container_rpc_client, container_process_gid, package_id, run_function) = {
|
||||
let (package_id, run_function) = {
|
||||
let state = state.borrow();
|
||||
let ctx: JsContext = state.borrow::<JsContext>().clone();
|
||||
(
|
||||
ctx.container_rpc_client,
|
||||
ctx.container_process_gid,
|
||||
ctx.package_id,
|
||||
ctx.run_function,
|
||||
)
|
||||
(ctx.package_id, ctx.run_function)
|
||||
};
|
||||
if let Some(rpc_client) = container_rpc_client {
|
||||
return rpc_client
|
||||
.request(
|
||||
embassy_container_init::Log,
|
||||
embassy_container_init::LogParams {
|
||||
gid: Some(container_process_gid),
|
||||
level: embassy_container_init::LogLevel::Info(input),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow!("{}: {:?}", e.message, e.data));
|
||||
}
|
||||
tracing::info!(
|
||||
package_id = tracing::field::display(&package_id),
|
||||
run_function = tracing::field::display(&run_function),
|
||||
@@ -1145,144 +1062,12 @@ mod fns {
|
||||
Ok(ctx.sandboxed)
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn send_signal(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
pid: u32,
|
||||
signal: u32,
|
||||
) -> Result<(), AnyError> {
|
||||
if let Some(rpc_client) = {
|
||||
let state = state.borrow();
|
||||
let ctx = state.borrow::<JsContext>();
|
||||
ctx.container_rpc_client.clone()
|
||||
} {
|
||||
rpc_client
|
||||
.request(
|
||||
SendSignal,
|
||||
SendSignalParams {
|
||||
pid: ProcessId(pid),
|
||||
signal,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow!("{}: {:?}", e.message, e.data))?;
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("No RpcClient for command operations"))
|
||||
}
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn signal_group(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
gid: u32,
|
||||
signal: u32,
|
||||
) -> Result<(), AnyError> {
|
||||
if let Some(rpc_client) = {
|
||||
let state = state.borrow();
|
||||
let ctx = state.borrow::<JsContext>();
|
||||
ctx.container_rpc_client.clone()
|
||||
} {
|
||||
rpc_client
|
||||
.request(
|
||||
SignalGroup,
|
||||
SignalGroupParams {
|
||||
gid: ProcessGroupId(gid),
|
||||
signal,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow!("{}: {:?}", e.message, e.data))?;
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
Err(anyhow!("No RpcClient for command operations"))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct StartCommand {
|
||||
process_id: ProcessId,
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn start_command(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
command: String,
|
||||
args: Vec<String>,
|
||||
output: OutputStrategy,
|
||||
timeout: Option<u64>,
|
||||
) -> Result<StartCommand, AnyError> {
|
||||
if let (gid, Some(rpc_client)) = {
|
||||
let state = state.borrow();
|
||||
let ctx = state.borrow::<JsContext>();
|
||||
(ctx.container_process_gid, ctx.container_rpc_client.clone())
|
||||
} {
|
||||
let pid = rpc_client
|
||||
.request(
|
||||
RunCommand,
|
||||
RunCommandParams {
|
||||
gid: Some(gid),
|
||||
command,
|
||||
args,
|
||||
output,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|e| anyhow!("{}: {:?}", e.message, e.data))?;
|
||||
|
||||
if let Some(timeout) = timeout {
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(Duration::from_millis(timeout)).await;
|
||||
if let Err(err) = rpc_client
|
||||
.request(SendSignal, SendSignalParams { pid, signal: 9 })
|
||||
.await
|
||||
.map_err(|e| anyhow!("{}: {:?}", e.message, e.data))
|
||||
{
|
||||
tracing::warn!("Could not kill process {pid:?}");
|
||||
tracing::debug!("{err:?}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok(StartCommand { process_id: pid })
|
||||
} else {
|
||||
Err(anyhow!("No RpcClient for command operations"))
|
||||
}
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn wait_command(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
pid: ProcessId,
|
||||
) -> Result<ResultType, AnyError> {
|
||||
if let Some(rpc_client) = {
|
||||
let state = state.borrow();
|
||||
let ctx = state.borrow::<JsContext>();
|
||||
ctx.container_rpc_client.clone()
|
||||
} {
|
||||
Ok(
|
||||
match rpc_client
|
||||
.request(embassy_container_init::Output, OutputParams { pid })
|
||||
.await
|
||||
{
|
||||
Ok(a) => ResultType::Result(json!(a)),
|
||||
Err(e) => ResultType::ErrorCode(
|
||||
e.code,
|
||||
match e.data {
|
||||
Some(Value::String(s)) => s,
|
||||
e => format!("{:?}", e),
|
||||
},
|
||||
),
|
||||
},
|
||||
)
|
||||
} else {
|
||||
Err(anyhow!("No RpcClient for command operations"))
|
||||
}
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn sleep(time_ms: u64) -> Result<(), AnyError> {
|
||||
tokio::time::sleep(Duration::from_millis(time_ms)).await;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{ActionId, HealthCheckId, PackageId};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum ProcedureName {
|
||||
Main, // Usually just run container
|
||||
CreateBackup,
|
||||
|
||||
Reference in New Issue
Block a user